Skip to content

Commit 11c7bd8

Browse files
committed
Cleanups
1 parent a05ecf8 commit 11c7bd8

File tree

8 files changed

+47
-43
lines changed

8 files changed

+47
-43
lines changed

src/Components/Endpoints/src/Binding/DefaultFormValuesSupplier.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Microsoft.AspNetCore.Components.Endpoints;
1414

15-
internal class DefaultFormValuesSupplier : IFormValueSupplier
15+
internal sealed class DefaultFormValuesSupplier : IFormValueSupplier
1616
{
1717
private static readonly MethodInfo _method = typeof(DefaultFormValuesSupplier)
1818
.GetMethod(
@@ -21,8 +21,8 @@ internal class DefaultFormValuesSupplier : IFormValueSupplier
2121
throw new InvalidOperationException($"Unable to find method '{nameof(DeserializeCore)}'.");
2222

2323
private readonly HttpContextFormDataProvider _formData;
24-
private readonly FormDataSerializerOptions _options = new();
25-
private static readonly ConcurrentDictionary<Type, Func<IReadOnlyDictionary<string, StringValues>, FormDataSerializerOptions, string, object>> _cache =
24+
private readonly FormDataMapperOptions _options = new();
25+
private static readonly ConcurrentDictionary<Type, Func<IReadOnlyDictionary<string, StringValues>, FormDataMapperOptions, string, object>> _cache =
2626
new();
2727

2828
public DefaultFormValuesSupplier(FormDataProvider formData)
@@ -61,18 +61,18 @@ public bool TryBind(string formName, Type valueType, [NotNullWhen(true)] out obj
6161
return false;
6262
}
6363

64-
private Func<IReadOnlyDictionary<string, StringValues>, FormDataSerializerOptions, string, object> CreateDeserializer(Type type) =>
64+
private Func<IReadOnlyDictionary<string, StringValues>, FormDataMapperOptions, string, object> CreateDeserializer(Type type) =>
6565
_method.MakeGenericMethod(type)
66-
.CreateDelegate<Func<IReadOnlyDictionary<string, StringValues>, FormDataSerializerOptions, string, object>>();
66+
.CreateDelegate<Func<IReadOnlyDictionary<string, StringValues>, FormDataMapperOptions, string, object>>();
6767

68-
private static object? DeserializeCore<T>(IReadOnlyDictionary<string, StringValues> form, FormDataSerializerOptions options, string value)
68+
private static object? DeserializeCore<T>(IReadOnlyDictionary<string, StringValues> form, FormDataMapperOptions options, string value)
6969
{
7070
// Form values are parsed according to the culture of the request, which is set to the current culture by the localization middleware.
7171
// Some form input types use the invariant culture when sending the data to the server. For those cases, we'll
7272
// provide a way to override the culture to use to parse that value.
7373
var reader = new FormDataReader(form, CultureInfo.CurrentCulture);
7474
reader.PushPrefix(value);
75-
return FormDataDeserializer.Deserialize<T>(reader, options);
75+
return FormDataMapper.Map<T>(reader, options);
7676
}
7777

7878
public bool CanConvertSingleValue(Type type)

src/Components/Endpoints/src/Binding/FormDataConverterOfT.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,5 @@ namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
55

66
internal abstract class FormDataConverter<T> : FormDataConverter
77
{
8-
internal abstract bool TryRead(ref FormDataReader context, Type type, FormDataSerializerOptions options, out T? result, out bool found);
9-
}
10-
11-
internal interface IFormDataConverterFactory
12-
{
13-
public static abstract bool CanConvert(Type type, FormDataSerializerOptions options);
14-
15-
public static abstract FormDataConverter CreateConverter(Type type, FormDataSerializerOptions options);
8+
internal abstract bool TryRead(ref FormDataReader context, Type type, FormDataMapperOptions options, out T? result, out bool found);
169
}

src/Components/Endpoints/src/Binding/FormDataDeserializer.cs renamed to src/Components/Endpoints/src/Binding/FormDataMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
55

6-
internal static class FormDataDeserializer
6+
internal static class FormDataMapper
77
{
8-
public static T? Deserialize<T>(
8+
public static T? Map<T>(
99
FormDataReader reader,
10-
FormDataSerializerOptions options)
10+
FormDataMapperOptions options)
1111
{
1212
try
1313
{

src/Components/Endpoints/src/Binding/FormDataSerializerOptions.cs renamed to src/Components/Endpoints/src/Binding/FormDataMapperOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
77

8-
internal class FormDataSerializerOptions
8+
internal sealed class FormDataMapperOptions
99
{
1010
private readonly ConcurrentDictionary<Type, FormDataConverter> _converters = new();
11-
private readonly List<Func<Type, FormDataSerializerOptions, FormDataConverter?>> _factories = new();
11+
private readonly List<Func<Type, FormDataMapperOptions, FormDataConverter?>> _factories = new();
1212

13-
public FormDataSerializerOptions()
13+
public FormDataMapperOptions()
1414
{
1515
_converters = new(WellKnownConverters.Converters);
1616

@@ -31,7 +31,7 @@ internal FormDataConverter<T> ResolveConverter<T>()
3131
return (FormDataConverter<T>)_converters.GetOrAdd(typeof(T), CreateConverter, this);
3232
}
3333

34-
private static FormDataConverter CreateConverter(Type type, FormDataSerializerOptions options)
34+
private static FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
3535
{
3636
FormDataConverter? converter;
3737
foreach (var factory in options._factories)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
5+
6+
internal interface IFormDataConverterFactory
7+
{
8+
public static abstract bool CanConvert(Type type, FormDataMapperOptions options);
9+
10+
public static abstract FormDataConverter CreateConverter(Type type, FormDataMapperOptions options);
11+
}

src/Components/Endpoints/src/Binding/NullableConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
77

8-
internal class NullableConverterFactory : IFormDataConverterFactory
8+
internal sealed class NullableConverterFactory : IFormDataConverterFactory
99
{
10-
public static bool CanConvert(Type type, FormDataSerializerOptions options)
10+
public static bool CanConvert(Type type, FormDataMapperOptions options)
1111
{
1212
var underlyingType = Nullable.GetUnderlyingType(type);
1313
return underlyingType != null && options.HasConverter(underlyingType);
1414
}
1515

16-
public static FormDataConverter CreateConverter(Type type, FormDataSerializerOptions options)
16+
public static FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
1717
{
1818
var underlyingType = Nullable.GetUnderlyingType(type);
1919
Debug.Assert(underlyingType != null);
@@ -35,7 +35,7 @@ public NullableConverter(FormDataConverter<T> nonNullableConverter)
3535
_nonNullableConverter = nonNullableConverter;
3636
}
3737

38-
internal override bool TryRead(ref FormDataReader context, Type type, FormDataSerializerOptions options, out T? result, out bool found)
38+
internal override bool TryRead(ref FormDataReader context, Type type, FormDataMapperOptions options, out T? result, out bool found)
3939
{
4040
if (!(_nonNullableConverter.TryRead(ref context, type, options, out var innerResult, out found) && found))
4141
{

src/Components/Endpoints/src/Binding/ParsableConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
55

6-
internal class ParsableConverterFactory : IFormDataConverterFactory
6+
internal sealed class ParsableConverterFactory : IFormDataConverterFactory
77
{
8-
public static bool CanConvert(Type type, FormDataSerializerOptions options)
8+
public static bool CanConvert(Type type, FormDataMapperOptions options)
99
{
1010
// returns whether type implements IParsable<T>
1111
return typeof(IParsable<>).MakeGenericType(type).IsAssignableFrom(type);
1212
}
1313

14-
public static FormDataConverter CreateConverter(Type type, FormDataSerializerOptions options)
14+
public static FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
1515
{
1616
return typeof(ParsableConverter<>)
1717
.MakeGenericType(type)
@@ -23,7 +23,7 @@ public static FormDataConverter CreateConverter(Type type, FormDataSerializerOpt
2323

2424
internal class ParsableConverter<T> : FormDataConverter<T>, ISingleValueConverter where T : IParsable<T>
2525
{
26-
internal override bool TryRead(ref FormDataReader reader, Type type, FormDataSerializerOptions options, out T? result, out bool found)
26+
internal override bool TryRead(ref FormDataReader reader, Type type, FormDataMapperOptions options, out T? result, out bool found)
2727
{
2828
found = reader.TryGetValue(out var value);
2929
if (found && T.TryParse(value, reader.Culture, out result))

src/Components/Endpoints/test/Binding/FormDataDeserializerTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void CanDeserialize_PrimitiveTypes(string value, Type type, object expect
1818
var collection = new Dictionary<string, StringValues>() { ["value"] = new StringValues(value) };
1919
var reader = new FormDataReader(collection, CultureInfo.InvariantCulture);
2020
reader.PushPrefix("value");
21-
var options = new FormDataSerializerOptions();
21+
var options = new FormDataMapperOptions();
2222

2323
// Act
2424
var result = CallDeserialize(reader, options, type);
@@ -35,7 +35,7 @@ public void CanDeserialize_NullablePrimitiveTypes(string value, Type type, objec
3535
var collection = new Dictionary<string, StringValues>() { ["value"] = new StringValues(value) };
3636
var reader = new FormDataReader(collection, CultureInfo.InvariantCulture);
3737
reader.PushPrefix("value");
38-
var options = new FormDataSerializerOptions();
38+
var options = new FormDataMapperOptions();
3939

4040
// Act
4141
var result = CallDeserialize(reader, options, type);
@@ -52,7 +52,7 @@ public void CanDeserialize_NullValues(Type type)
5252
var collection = new Dictionary<string, StringValues>() { };
5353
var reader = new FormDataReader(collection, CultureInfo.InvariantCulture);
5454
reader.PushPrefix("value");
55-
var options = new FormDataSerializerOptions();
55+
var options = new FormDataMapperOptions();
5656

5757
// Act
5858
var result = CallDeserialize(reader, options, type);
@@ -69,10 +69,10 @@ public void CanDeserialize_CustomParsableTypes()
6969
var collection = new Dictionary<string, StringValues>() { ["value"] = new StringValues("(1,1)") };
7070
var reader = new FormDataReader(collection, CultureInfo.InvariantCulture);
7171
reader.PushPrefix("value");
72-
var options = new FormDataSerializerOptions();
72+
var options = new FormDataMapperOptions();
7373

7474
// Act
75-
var result = FormDataDeserializer.Deserialize<Point>(reader, options);
75+
var result = FormDataMapper.Map<Point>(reader, options);
7676

7777
// Assert
7878
Assert.Equal(expected, result);
@@ -87,10 +87,10 @@ public void CanDeserialize_NullableCustomParsableTypes()
8787
var collection = new Dictionary<string, StringValues>() { ["value"] = new StringValues("(1,1)") };
8888
var reader = new FormDataReader(collection, CultureInfo.InvariantCulture);
8989
reader.PushPrefix("value");
90-
var options = new FormDataSerializerOptions();
90+
var options = new FormDataMapperOptions();
9191

9292
// Act
93-
var result = FormDataDeserializer.Deserialize<ValuePoint?>(reader, options);
93+
var result = FormDataMapper.Map<ValuePoint?>(reader, options);
9494

9595
// Assert
9696
Assert.Equal(expected, result);
@@ -103,10 +103,10 @@ public void CanDeserialize_NullableCustomParsableTypes_NullValue()
103103
var collection = new Dictionary<string, StringValues>() { };
104104
var reader = new FormDataReader(collection, CultureInfo.InvariantCulture);
105105
reader.PushPrefix("value");
106-
var options = new FormDataSerializerOptions();
106+
var options = new FormDataMapperOptions();
107107

108108
// Act
109-
var result = FormDataDeserializer.Deserialize<ValuePoint?>(reader, options);
109+
var result = FormDataMapper.Map<ValuePoint?>(reader, options);
110110

111111
// Assert
112112
Assert.Null(result);
@@ -240,11 +240,11 @@ public static TheoryData<string, Type, object> PrimitiveTypesData
240240
}
241241
}
242242

243-
private object CallDeserialize(FormDataReader reader, FormDataSerializerOptions options, Type type)
243+
private object CallDeserialize(FormDataReader reader, FormDataMapperOptions options, Type type)
244244
{
245-
var method = typeof(FormDataDeserializer)
246-
.GetMethod("Deserialize", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public) ??
247-
throw new InvalidOperationException("Unable to find method 'Deserialize'.");
245+
var method = typeof(FormDataMapper)
246+
.GetMethod("Map", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public) ??
247+
throw new InvalidOperationException("Unable to find method 'Map'.");
248248

249249
return method.MakeGenericMethod(type).Invoke(null, new object[] { reader, options })!;
250250
}

0 commit comments

Comments
 (0)