Skip to content

Commit c53f18a

Browse files
authored
Add complex form binding support to RDF (#48790)
* Add complex form binding support to RDF * Address feedback from peer review
1 parent da572dc commit c53f18a

20 files changed

+353
-7
lines changed

src/Components/Endpoints/src/Binding/Factories/CollectionConverterFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Microsoft.Extensions.Internal;
56

67
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
@@ -9,6 +10,8 @@ internal class CollectionConverterFactory : IFormDataConverterFactory
910
{
1011
public static readonly CollectionConverterFactory Instance = new();
1112

13+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
14+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1215
public bool CanConvert(Type type, FormDataMapperOptions options)
1316
{
1417
var enumerable = ClosedGenericMatcher.ExtractGenericInterface(type, typeof(IEnumerable<>));
@@ -28,6 +31,8 @@ public bool CanConvert(Type type, FormDataMapperOptions options)
2831
return factory.CanConvert(type, options);
2932
}
3033

34+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
35+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
3136
public FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
3237
{
3338
ArgumentNullException.ThrowIfNull(type);

src/Components/Endpoints/src/Binding/Factories/Collections/ConcreteTypeCollectionConverterFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
5+
46
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
57

68
internal class ConcreteTypeCollectionConverterFactory<TCollection, TElement>
@@ -9,8 +11,12 @@ internal class ConcreteTypeCollectionConverterFactory<TCollection, TElement>
911
public static readonly ConcreteTypeCollectionConverterFactory<TCollection, TElement> Instance =
1012
new();
1113

14+
[UnconditionalSuppressMessage("Trimming", "IL2046", Justification = "This derived implementation doesn't require unreferenced code like other implementations of the interface.")]
15+
[UnconditionalSuppressMessage("AOT", "IL3051", Justification = "This derived implementation doesn't use dynamic code like other implementations of the interface.")]
1216
public bool CanConvert(Type _, FormDataMapperOptions options) => true;
1317

18+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
19+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1420
public FormDataConverter CreateConverter(Type _, FormDataMapperOptions options)
1521
{
1622
// Resolve the element type converter

src/Components/Endpoints/src/Binding/Factories/Collections/TypedCollectionConverterFactory.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@
44
using System.Collections.Concurrent;
55
using System.Collections.Immutable;
66
using System.Collections.ObjectModel;
7+
using System.Diagnostics.CodeAnalysis;
78

89
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
910

1011
internal abstract class TypedCollectionConverterFactory : IFormDataConverterFactory
1112
{
13+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
14+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1215
public abstract bool CanConvert(Type type, FormDataMapperOptions options);
1316

17+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
18+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1419
public abstract FormDataConverter CreateConverter(Type type, FormDataMapperOptions options);
1520
}
1621

1722
internal sealed class TypedCollectionConverterFactory<TCollection, TElement> : TypedCollectionConverterFactory
1823
{
24+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
25+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1926
public override bool CanConvert(Type _, FormDataMapperOptions options)
2027
{
2128
// Resolve the element type converter
@@ -101,6 +108,8 @@ var _ when type.IsAssignableTo(typeof(ICollection<TElement>)) && type.GetConstru
101108
// the Queue directly as the buffer (queues don't implement ICollection<T>, so the adapter uses Push instead),
102109
// or for ImmutableXXX<T> we either use ImmuttableXXX.CreateBuilder<T> to create a builder we use as a buffer,
103110
// or collect the collection into an array buffer and call CreateRange to build the final collection.
111+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
112+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
104113
public override FormDataConverter CreateConverter(Type _, FormDataMapperOptions options)
105114
{
106115
// Resolve the element type converter
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
5+
46
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
57

68
internal abstract class ComplexTypeExpressionConverterFactory
79
{
10+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
11+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
812
internal abstract FormDataConverter CreateConverter(Type type, FormDataMapperOptions options);
913
}

src/Components/Endpoints/src/Binding/Factories/ComplexType/ComplexTypeExpressionConverterFactoryOfT.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Linq.Expressions;
56
using Microsoft.Extensions.Internal;
67

78
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
89

910
internal sealed class ComplexTypeExpressionConverterFactory<T> : ComplexTypeExpressionConverterFactory
1011
{
12+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
13+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1114
internal override CompiledComplexTypeConverter<T> CreateConverter(Type type, FormDataMapperOptions options)
1215
{
1316
var body = CreateConverterBody(type, options);
1417
return new CompiledComplexTypeConverter<T>(body);
1518
}
1619

20+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
21+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1722
private CompiledComplexTypeConverter<T>.ConverterDelegate CreateConverterBody(Type type, FormDataMapperOptions options)
1823
{
1924
var properties = PropertyHelper.GetVisibleProperties(type);

src/Components/Endpoints/src/Binding/Factories/ComplexTypeConverterFactory.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Microsoft.Extensions.Internal;
56

67
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
@@ -11,6 +12,8 @@ internal class ComplexTypeConverterFactory : IFormDataConverterFactory
1112
{
1213
internal static readonly ComplexTypeConverterFactory Instance = new();
1314

15+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
16+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1417
public bool CanConvert(Type type, FormDataMapperOptions options)
1518
{
1619
if (type.GetConstructor(Type.EmptyTypes) == null && !type.IsValueType)
@@ -105,7 +108,8 @@ public bool CanConvert(Type type, FormDataMapperOptions options)
105108
// return converterFunc(ref reader, type, options, out result, out found);
106109
// }
107110
// }
108-
111+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
112+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
109113
public FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
110114
{
111115
if (Activator.CreateInstance(typeof(ComplexTypeExpressionConverterFactory<>).MakeGenericType(type))

src/Components/Endpoints/src/Binding/Factories/Dictionary/ConcreteTypeDictionaryConverterFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
5+
46
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
57

68
internal sealed class ConcreteTypeDictionaryConverterFactory<TDictionary, TKey, TValue> : IFormDataConverterFactory
79
where TKey : IParsable<TKey>
810
{
911
public static readonly ConcreteTypeDictionaryConverterFactory<TDictionary, TKey, TValue> Instance = new();
1012

13+
[UnconditionalSuppressMessage("Trimming", "IL2046", Justification = "This derived implementation doesn't require unreferenced code like other implementations of the interface.")]
14+
[UnconditionalSuppressMessage("AOT", "IL3051", Justification = "This derived implementation doesn't use dynamic code like other implementations of the interface.")]
1115
public bool CanConvert(Type type, FormDataMapperOptions options) => true;
1216

17+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
18+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1319
public FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
1420
{
1521
// Resolve the element type converter

src/Components/Endpoints/src/Binding/Factories/Dictionary/TypedDictionaryConverterFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
using System.Collections.Concurrent;
55
using System.Collections.Immutable;
66
using System.Collections.ObjectModel;
7+
using System.Diagnostics.CodeAnalysis;
78

89
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
910

1011
internal sealed class TypedDictionaryConverterFactory<TDictionaryType, TKey, TValue> : IFormDataConverterFactory
1112
where TKey : IParsable<TKey>
1213
{
14+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
15+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1316
public bool CanConvert(Type type, FormDataMapperOptions options)
1417
{
1518
// Resolve the value type converter
@@ -70,6 +73,8 @@ var _ when type.IsAssignableTo(typeof(IDictionary<TKey, TValue>)) && type.GetCon
7073
return false;
7174
}
7275

76+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
77+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
7378
public FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
7479
{
7580
// Resolve the value type converter

src/Components/Endpoints/src/Binding/Factories/DictionaryConverterFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Microsoft.Extensions.Internal;
56

67
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
@@ -9,6 +10,8 @@ internal class DictionaryConverterFactory : IFormDataConverterFactory
910
{
1011
internal static readonly DictionaryConverterFactory Instance = new();
1112

13+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
14+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1215
public bool CanConvert(Type type, FormDataMapperOptions options)
1316
{
1417
// Type must implement IDictionary<TKey, TValue> IReadOnlyDictionary<TKey, TValue>
@@ -58,6 +61,8 @@ public bool CanConvert(Type type, FormDataMapperOptions options)
5861
return factory.CanConvert(type, options);
5962
}
6063

64+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
65+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
6166
public FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
6267
{
6368
// Type must implement IDictionary<TKey, TValue> IReadOnlyDictionary<TKey, TValue>

src/Components/Endpoints/src/Binding/Factories/NullableConverterFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
56

67
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
78

89
internal sealed class NullableConverterFactory : IFormDataConverterFactory
910
{
1011
public static readonly NullableConverterFactory Instance = new();
1112

13+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
14+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1215
public bool CanConvert(Type type, FormDataMapperOptions options)
1316
{
1417
var underlyingType = Nullable.GetUnderlyingType(type);
1518
return underlyingType != null && options.ResolveConverter(underlyingType) != null;
1619
}
1720

21+
[RequiresDynamicCode(FormBindingHelpers.RequiresDynamicCodeMessage)]
22+
[RequiresUnreferencedCode(FormBindingHelpers.RequiresUnreferencedCodeMessage)]
1823
public FormDataConverter CreateConverter(Type type, FormDataMapperOptions options)
1924
{
2025
var underlyingType = Nullable.GetUnderlyingType(type);

0 commit comments

Comments
 (0)