Skip to content

Commit 99407d1

Browse files
author
StickFun
committed
Added string arrays to simple binding
1 parent 5d0e0d0 commit 99407d1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public static partial class RequestDelegateFactory
129129
private static readonly string[] FormFileContentType = new[] { "multipart/form-data" };
130130
private static readonly string[] FormContentType = new[] { "multipart/form-data", "application/x-www-form-urlencoded" };
131131
private static readonly string[] PlaintextContentType = new[] { "text/plain" };
132+
private static readonly Type[] StringTypes = new[] {typeof(string), typeof(StringValues), typeof(StringValues?) };
132133

133134
/// <summary>
134135
/// Returns metadata inferred automatically for the <see cref="RequestDelegate"/> created by <see cref="Create(Delegate, RequestDelegateFactoryOptions?, RequestDelegateMetadataResult?)"/>.
@@ -791,11 +792,11 @@ private static Expression CreateArgument(ParameterInfo parameter, RequestDelegat
791792
// For complex types, leverage the shared form binding infrastructure. For example,
792793
// shared form binding does not currently only supports types that implement IParsable
793794
// while RDF's binding implementation supports all TryParse implementations.
794-
var useSimpleBinding = parameter.ParameterType == typeof(string) ||
795-
parameter.ParameterType == typeof(StringValues) ||
796-
parameter.ParameterType == typeof(StringValues?) ||
795+
var useSimpleBinding = StringTypes.Contains(parameter.ParameterType) ||
797796
ParameterBindingMethodCache.Instance.HasTryParseMethod(parameter.ParameterType) ||
798-
(parameter.ParameterType.IsArray && ParameterBindingMethodCache.Instance.HasTryParseMethod(parameter.ParameterType.GetElementType()!));
797+
(parameter.ParameterType.IsArray &&
798+
(StringTypes.Contains(parameter.ParameterType.GetElementType()) ||
799+
ParameterBindingMethodCache.Instance.HasTryParseMethod(parameter.ParameterType.GetElementType()!)));
799800
hasTryParse = useSimpleBinding;
800801
return useSimpleBinding
801802
? BindParameterFromFormItem(parameter, formAttribute.Name ?? parameter.Name, factoryContext)

0 commit comments

Comments
 (0)