Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit b42d501

Browse files
committed
React to string[] -> StringValues changes.
1 parent 774219b commit b42d501

File tree

46 files changed

+184
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+184
-309
lines changed

src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,13 @@ public void SetModelValue([NotNull] string key, ValueProviderResult valueProvide
391391
{
392392
rawValue = null;
393393
}
394-
else if (valueProviderResult.Value != null)
395-
{
396-
rawValue = valueProviderResult.Value;
397-
}
398394
else if (valueProviderResult.Length == 1)
399395
{
400396
rawValue = valueProviderResult.Values[0];
401397
}
402398
else
403399
{
404-
rawValue = valueProviderResult.Values;
400+
rawValue = (string[])valueProviderResult.Values;
405401
}
406402

407403
SetModelValue(key, rawValue, (string)valueProviderResult);

src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs

Lines changed: 18 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
using System;
55
using System.Collections;
66
using System.Collections.Generic;
7-
using System.Diagnostics;
87
using System.Globalization;
9-
using Microsoft.Framework.Internal;
8+
using Microsoft.AspNet.Primitives;
109

1110
namespace Microsoft.AspNet.Mvc.ModelBinding
1211
{
@@ -38,9 +37,9 @@ public struct ValueProviderResult : IEquatable<ValueProviderResult>, IEnumerable
3837
/// <summary>
3938
/// Creates a new <see cref="ValueProviderResult"/> using <see cref="CultureInfo.InvariantCulture"/>.
4039
/// </summary>
41-
/// <param name="value">The submitted value.</param>
42-
public ValueProviderResult(string value)
43-
: this(value, _invariantCulture)
40+
/// <param name="values">The submitted values.</param>
41+
public ValueProviderResult(StringValues values)
42+
: this(values, _invariantCulture)
4443
{
4544
}
4645

@@ -49,88 +48,36 @@ public ValueProviderResult(string value)
4948
/// </summary>
5049
/// <param name="value">The submitted value.</param>
5150
/// <param name="culture">The <see cref="CultureInfo"/> associated with this value.</param>
52-
public ValueProviderResult(string value, CultureInfo culture)
51+
public ValueProviderResult(StringValues values, CultureInfo culture)
5352
{
54-
if (value == null)
55-
{
56-
Value = null;
57-
Values = None.Values;
58-
}
59-
else
60-
{
61-
Value = value;
62-
Values = null;
63-
}
64-
53+
Values = values;
6554
Culture = culture ?? _invariantCulture;
6655
}
6756

68-
/// <summary>
69-
/// Creates a new <see cref="ValueProviderResult"/> using <see cref="CultureInfo.InvariantCulture"/>.
70-
/// </summary>
71-
/// <param name="values">The submitted values.</param>
72-
public ValueProviderResult(string[] values)
73-
: this(values, _invariantCulture)
74-
{
75-
}
76-
77-
/// <summary>
78-
/// Creates a new <see cref="ValueProviderResult"/>.
79-
/// </summary>
80-
/// <param name="values">The submitted values.</param>
81-
/// <param name="culture">The <see cref="CultureInfo"/> associated with these values.</param>
82-
public ValueProviderResult(string[] values, CultureInfo culture)
83-
{
84-
if (values == null)
85-
{
86-
Value = null;
87-
Values = None.Values;
88-
}
89-
else
90-
{
91-
Value = null;
92-
Values = values;
93-
}
94-
95-
Culture = culture;
96-
}
97-
9857
/// <summary>
9958
/// Gets or sets the <see cref="CultureInfo"/> associated with the values.
10059
/// </summary>
10160
public CultureInfo Culture { get; private set; }
10261

10362
/// <summary>
104-
/// Gets or sets a single value. Will be <c>null</c> if multiple values are present.
63+
/// Gets or sets the values.
10564
/// </summary>
106-
public string Value { get; private set; }
107-
108-
/// <summary>
109-
/// Gets or sets an array of values. Will be <c>null</c> if only a single value was provided.
110-
/// </summary>
111-
public string[] Values { get; private set; }
65+
public StringValues Values { get; private set; }
11266

11367
/// <summary>
11468
/// Gets the first value based on the order values were provided in the request. Use <see cref="FirstValue"/>
115-
/// to get a single value for processing regarless of whether a single or multiple values were provided
69+
/// to get a single value for processing regardless of whether a single or multiple values were provided
11670
/// in the request.
11771
/// </summary>
11872
public string FirstValue
11973
{
12074
get
12175
{
122-
if (Value != null)
123-
{
124-
return Value;
125-
}
126-
else if (Values != null && Values.Length > 0)
127-
{
128-
return Values[0];
129-
}
130-
else
76+
if (Values.Count == 0)
13177
{
13278
return null;
13379
}
80+
return Values[0];
13481
}
13582
}
13683

@@ -141,18 +88,7 @@ public int Length
14188
{
14289
get
14390
{
144-
if (Values != null)
145-
{
146-
return Values.Length;
147-
}
148-
else if (Value != null)
149-
{
150-
return 1;
151-
}
152-
else
153-
{
154-
return 0;
155-
}
91+
return Values.Count;
15692
}
15793
}
15894

@@ -198,12 +134,12 @@ public override string ToString()
198134
}
199135

200136
/// <summary>
201-
/// Gets an <see cref="Enumerator"/> for this <see cref="ValueProviderResult"/>.
137+
/// Gets an <see cref="IEnumerator<string>"/> for this <see cref="ValueProviderResult"/>.
202138
/// </summary>
203-
/// <returns>An <see cref="Enumerator"/>.</returns>
204-
public Enumerator GetEnumerator()
139+
/// <returns>An <see cref="IEnumerator<string>"/>.</returns>
140+
public IEnumerator<string> GetEnumerator()
205141
{
206-
return new Enumerator(this);
142+
return ((IEnumerable<string>)Values).GetEnumerator();
207143
}
208144

209145
/// <inheritdoc />
@@ -225,22 +161,7 @@ IEnumerator IEnumerable.GetEnumerator()
225161
/// <param name="result">The <see cref="ValueProviderResult"/>.</param>
226162
public static explicit operator string(ValueProviderResult result)
227163
{
228-
if (result.Values == null)
229-
{
230-
return result.Value;
231-
}
232-
else if (result.Values.Length == 0)
233-
{
234-
return null;
235-
}
236-
else if (result.Values.Length == 1)
237-
{
238-
return result.Values[0];
239-
}
240-
else
241-
{
242-
return string.Join(",", result.Values);
243-
}
164+
return result.Values;
244165
}
245166

246167
/// <summary>
@@ -250,18 +171,7 @@ public static explicit operator string(ValueProviderResult result)
250171
/// <param name="result">The <see cref="ValueProviderResult"/>.</param>
251172
public static explicit operator string[](ValueProviderResult result)
252173
{
253-
if (result.Values != null)
254-
{
255-
return result.Values;
256-
}
257-
else if (result.Value != null)
258-
{
259-
return new string[] { result.Value };
260-
}
261-
else
262-
{
263-
return None.Values;
264-
}
174+
return result.Values;
265175
}
266176

267177
/// <summary>
@@ -285,71 +195,5 @@ public static explicit operator string[](ValueProviderResult result)
285195
{
286196
return !x.Equals(y);
287197
}
288-
289-
/// <summary>
290-
/// An enumerator for <see cref="ValueProviderResult"/>.
291-
/// </summary>
292-
public struct Enumerator : IEnumerator<string>
293-
{
294-
private readonly ValueProviderResult _result;
295-
private readonly int _length;
296-
private int _index;
297-
298-
/// <summary>
299-
/// Creates a new <see cref="Enumerator"/>.
300-
/// </summary>
301-
/// <param name="result">The <see cref="ValueProviderResult"/>.</param>
302-
public Enumerator(ValueProviderResult result)
303-
{
304-
_result = result;
305-
_index = -1;
306-
_length = result.Length;
307-
Current = null;
308-
}
309-
310-
/// <inheritdoc />
311-
public string Current { get; private set; }
312-
313-
/// <inheritdoc />
314-
object IEnumerator.Current => Current;
315-
316-
/// <inheritdoc />
317-
public void Dispose()
318-
{
319-
}
320-
321-
/// <inheritdoc />
322-
public bool MoveNext()
323-
{
324-
++_index;
325-
if (_index < _length)
326-
{
327-
if (_result.Values != null)
328-
{
329-
Debug.Assert(_index < _result.Values.Length);
330-
Current = _result.Values[_index];
331-
return true;
332-
}
333-
else if (_result.Value != null && _index == 0)
334-
{
335-
Current = _result.Value;
336-
return true;
337-
}
338-
else
339-
{
340-
return false;
341-
}
342-
}
343-
344-
Current = null;
345-
return false;
346-
}
347-
348-
/// <inheritdoc />
349-
public void Reset()
350-
{
351-
_index = -1;
352-
}
353-
}
354198
}
355199
}

src/Microsoft.AspNet.Mvc.Core/CreatedAtActionResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNet.Mvc.Core;
88
using Microsoft.Framework.DependencyInjection;
99
using Microsoft.Framework.Internal;
10+
using Microsoft.Net.Http.Headers;
1011

1112
namespace Microsoft.AspNet.Mvc
1213
{
@@ -73,7 +74,7 @@ protected override void OnFormatting([NotNull] ActionContext context)
7374
throw new InvalidOperationException(Resources.NoRoutesMatched);
7475
}
7576

76-
context.HttpContext.Response.Headers.Set("Location", url);
77+
context.HttpContext.Response.Headers[HeaderNames.Location] = url;
7778
}
7879
}
7980
}

src/Microsoft.AspNet.Mvc.Core/CreatedAtRouteResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNet.Mvc.Core;
88
using Microsoft.Framework.DependencyInjection;
99
using Microsoft.Framework.Internal;
10+
using Microsoft.Net.Http.Headers;
1011

1112
namespace Microsoft.AspNet.Mvc
1213
{
@@ -70,7 +71,7 @@ protected override void OnFormatting([NotNull] ActionContext context)
7071
throw new InvalidOperationException(Resources.NoRoutesMatched);
7172
}
7273

73-
context.HttpContext.Response.Headers.Set("Location", url);
74+
context.HttpContext.Response.Headers[HeaderNames.Location] = url;
7475
}
7576
}
7677
}

src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using Microsoft.AspNet.Http;
66
using Microsoft.Framework.Internal;
7+
using Microsoft.Net.Http.Headers;
78

89
namespace Microsoft.AspNet.Mvc
910
{
@@ -50,7 +51,7 @@ public string Location
5051
/// <inheritdoc />
5152
protected override void OnFormatting([NotNull] ActionContext context)
5253
{
53-
context.HttpContext.Response.Headers.Set("Location", Location);
54+
context.HttpContext.Response.Headers[HeaderNames.Location] = Location;
5455
}
5556
}
5657
}

src/Microsoft.AspNet.Mvc.Core/FileResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public override Task ExecuteResultAsync([NotNull] ActionContext context)
6868
// basis for the actual filename, where possible.
6969
var cd = new ContentDispositionHeaderValue("attachment");
7070
cd.SetHttpFileName(FileDownloadName);
71-
context.HttpContext.Response.Headers.Set(HeaderNames.ContentDisposition, cd.ToString());
71+
context.HttpContext.Response.Headers[HeaderNames.ContentDisposition] = cd.ToString();
7272
}
7373

7474
// We aren't flowing the cancellation token appropriately, see

src/Microsoft.AspNet.Mvc.Core/HttpMethodConstraint.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Collections.ObjectModel;
77
using System.Linq;
8+
using Microsoft.AspNet.Primitives;
89
using Microsoft.Framework.Internal;
910

1011
namespace Microsoft.AspNet.Mvc
@@ -62,12 +63,12 @@ public bool Accept([NotNull] ActionConstraintContext context)
6263
if (request.Headers.ContainsKey(OriginHeader))
6364
{
6465
// Update the http method if it is preflight request.
65-
var accessControlRequestMethod = request.Headers.Get(AccessControlRequestMethod);
66+
var accessControlRequestMethod = request.Headers[AccessControlRequestMethod];
6667
if (string.Equals(
6768
request.Method,
6869
PreflightHttpMethod,
6970
StringComparison.Ordinal) &&
70-
accessControlRequestMethod != null)
71+
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
7172
{
7273
method = accessControlRequestMethod;
7374
}

src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using Microsoft.AspNet.Http;
99
using Microsoft.AspNet.Http.Internal;
10+
using Microsoft.AspNet.Primitives;
1011
using Microsoft.Framework.Internal;
1112

1213
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -42,7 +43,7 @@ public async Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingConte
4243
}
4344
else
4445
{
45-
model = new FormCollection(new Dictionary<string, string[]>());
46+
model = new FormCollection(new Dictionary<string, StringValues>());
4647
}
4748

4849
var validationNode =

0 commit comments

Comments
 (0)