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

Commit 6331a9c

Browse files
committed
React to string[] -> StringValues changes.
1 parent e61ebca commit 6331a9c

File tree

42 files changed

+154
-126
lines changed

Some content is hidden

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

42 files changed

+154
-126
lines changed

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 =

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reflection;
88
#endif
99
using System.Threading.Tasks;
10+
using Microsoft.AspNet.Primitives;
1011
using Microsoft.Framework.Internal;
1112

1213
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -36,7 +37,7 @@ protected override Task<ModelBindingResult> BindModelCoreAsync([NotNull] ModelBi
3637
object model = null;
3738
if (bindingContext.ModelType == typeof(string))
3839
{
39-
var value = request.Headers.Get(headerName);
40+
string value = request.Headers[headerName];
4041
if (value != null)
4142
{
4243
model = value;
@@ -45,7 +46,7 @@ protected override Task<ModelBindingResult> BindModelCoreAsync([NotNull] ModelBi
4546
else if (typeof(IEnumerable<string>).IsAssignableFrom(bindingContext.ModelType))
4647
{
4748
var values = request.Headers.GetCommaSeparatedValues(headerName);
48-
if (values != null)
49+
if (values.Count > 0)
4950
{
5051
model = ModelBindingHelper.ConvertValuesToCollectionType(
5152
bindingContext.ModelType,
@@ -61,7 +62,7 @@ protected override Task<ModelBindingResult> BindModelCoreAsync([NotNull] ModelBi
6162
bindingContext.ModelMetadata,
6263
model);
6364

64-
var attemptedValue = (model as string) ?? request.Headers.Get(headerName);
65+
var attemptedValue = (model as string) ?? request.Headers[headerName];
6566
var valueProviderResult = new ValueProviderResult(model, attemptedValue, CultureInfo.InvariantCulture);
6667
bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult);
6768
}

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics;
77
using System.Globalization;
88
using System.Threading.Tasks;
9+
using Microsoft.AspNet.Primitives;
910
using Microsoft.Framework.Internal;
1011

1112
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -16,10 +17,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
1617
/// </summary>
1718
public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider
1819
{
19-
private readonly Func<Task<IDictionary<string, string[]>>> _valuesFactory;
20+
private readonly Func<Task<IDictionary<string, StringValues>>> _valuesFactory;
2021

2122
private PrefixContainer _prefixContainer;
22-
private IDictionary<string, string[]> _values;
23+
private IDictionary<string, StringValues> _values;
2324

2425
/// <summary>
2526
/// Initializes a new instance of the <see cref="DictionaryBasedValueProvider"/> class.
@@ -29,7 +30,7 @@ public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableVa
2930
/// <param name="culture">The culture to return with ValueProviderResult instances.</param>
3031
public JQueryFormValueProvider(
3132
[NotNull] BindingSource bindingSource,
32-
[NotNull] Func<Task<IDictionary<string, string[]>>> valuesFactory,
33+
[NotNull] Func<Task<IDictionary<string, StringValues>>> valuesFactory,
3334
CultureInfo culture)
3435
: base(bindingSource)
3536
{
@@ -40,7 +41,7 @@ public JQueryFormValueProvider(
4041
// Internal for testing.
4142
internal JQueryFormValueProvider(
4243
[NotNull] BindingSource bindingSource,
43-
[NotNull] IDictionary<string, string[]> values,
44+
[NotNull] IDictionary<string, StringValues> values,
4445
CultureInfo culture)
4546
: base(bindingSource)
4647
{
@@ -70,22 +71,26 @@ public override async Task<ValueProviderResult> GetValueAsync(string key)
7071
{
7172
var dictionary = await GetDictionary();
7273

73-
string[] values;
74-
if (dictionary.TryGetValue(key, out values) && values != null && values.Length > 0)
74+
StringValues values;
75+
if (dictionary.TryGetValue(key, out values) && values.Count > 0)
7576
{
76-
// Success.
77-
if (values.Length == 1)
77+
if (values.Count == 1)
7878
{
79-
return new ValueProviderResult(values[0], values[0], Culture);
79+
var value = (string)values;
80+
return new ValueProviderResult(value, value, Culture);
81+
}
82+
else
83+
{
84+
var rawValue = (string[])values;
85+
var value = (string)values;
86+
return new ValueProviderResult(rawValue, value, Culture);
8087
}
81-
82-
return new ValueProviderResult(values, string.Join(",", values), Culture);
8388
}
8489

8590
return null;
8691
}
8792

88-
private async Task<IDictionary<string, string[]>> GetDictionary()
93+
private async Task<IDictionary<string, StringValues>> GetDictionary()
8994
{
9095
if (_values == null)
9196
{

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading.Tasks;
99
using Microsoft.AspNet.Http;
1010
using Microsoft.AspNet.Mvc.Core;
11+
using Microsoft.AspNet.Primitives;
1112
using Microsoft.Framework.Internal;
1213

1314
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -29,11 +30,11 @@ public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext con
2930
return null;
3031
}
3132

32-
private static async Task<IDictionary<string, string[]>> GetValueCollectionAsync(HttpRequest request)
33+
private static async Task<IDictionary<string, StringValues>> GetValueCollectionAsync(HttpRequest request)
3334
{
3435
var formCollection = await request.ReadFormAsync();
3536

36-
var dictionary = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
37+
var dictionary = new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase);
3738
foreach (var entry in formCollection)
3839
{
3940
var key = NormalizeJQueryToMvc(entry.Key);

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

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

1213
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -80,21 +81,21 @@ public virtual async Task<IDictionary<string, string>> GetKeysFromPrefixAsync([N
8081
public override async Task<ValueProviderResult> GetValueAsync([NotNull] string key)
8182
{
8283
var collection = await GetValueCollectionAsync();
83-
var values = collection.GetValues(key);
84+
var values = collection[key];
8485

8586
ValueProviderResult result;
86-
if (values == null)
87+
if (values.Count == 0)
8788
{
8889
result = null;
8990
}
9091
else if (values.Count == 1)
9192
{
92-
var value = (string)values[0];
93+
var value = (string)values;
9394
result = new ValueProviderResult(value, value, _culture);
9495
}
9596
else
9697
{
97-
result = new ValueProviderResult(values, _values.Get(key), _culture);
98+
result = new ValueProviderResult((string[])values, _values[key], _culture);
9899
}
99100

100101
return result;

0 commit comments

Comments
 (0)