@@ -17,7 +17,8 @@ namespace Microsoft.AspNetCore.Http
17
17
/// </summary>
18
18
public static partial class RequestDelegateFactory
19
19
{
20
- private static readonly NullabilityInfoContext NullabilityContext = new NullabilityInfoContext ( ) ;
20
+ private static readonly NullabilityInfoContext NullabilityContext = new ( ) ;
21
+ private static readonly TryParseMethodCache TryParseMethodCache = new ( ) ;
21
22
22
23
private static readonly MethodInfo ExecuteTaskOfTMethod = typeof ( RequestDelegateFactory ) . GetMethod ( nameof ( ExecuteTask ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
23
24
private static readonly MethodInfo ExecuteTaskOfStringMethod = typeof ( RequestDelegateFactory ) . GetMethod ( nameof ( ExecuteTaskOfString ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
@@ -42,7 +43,6 @@ public static partial class RequestDelegateFactory
42
43
private static readonly ParameterExpression HttpContextExpr = Expression . Parameter ( typeof ( HttpContext ) , "httpContext" ) ;
43
44
private static readonly ParameterExpression BodyValueExpr = Expression . Parameter ( typeof ( object ) , "bodyValue" ) ;
44
45
private static readonly ParameterExpression WasParamCheckFailureExpr = Expression . Variable ( typeof ( bool ) , "wasParamCheckFailure" ) ;
45
- private static readonly ParameterExpression TempSourceStringExpr = TryParseMethodCache . TempSourceStringExpr ;
46
46
47
47
private static readonly MemberExpression RequestServicesExpr = Expression . Property ( HttpContextExpr , nameof ( HttpContext . RequestServices ) ) ;
48
48
private static readonly MemberExpression HttpRequestExpr = Expression . Property ( HttpContextExpr , nameof ( HttpContext . Request ) ) ;
@@ -55,8 +55,8 @@ public static partial class RequestDelegateFactory
55
55
private static readonly MemberExpression StatusCodeExpr = Expression . Property ( HttpResponseExpr , nameof ( HttpResponse . StatusCode ) ) ;
56
56
private static readonly MemberExpression CompletedTaskExpr = Expression . Property ( null , ( PropertyInfo ) GetMemberInfo < Func < Task > > ( ( ) => Task . CompletedTask ) ) ;
57
57
58
- private static readonly BinaryExpression TempSourceStringNotNullExpr = Expression . NotEqual ( TempSourceStringExpr , Expression . Constant ( null ) ) ;
59
- private static readonly BinaryExpression TempSourceStringNullExpr = Expression . Equal ( TempSourceStringExpr , Expression . Constant ( null ) ) ;
58
+ private static readonly BinaryExpression TempSourceStringNotNullExpr = Expression . NotEqual ( TryParseMethodCache . TempSourceStringExpr , Expression . Constant ( null ) ) ;
59
+ private static readonly BinaryExpression TempSourceStringNullExpr = Expression . Equal ( TryParseMethodCache . TempSourceStringExpr , Expression . Constant ( null ) ) ;
60
60
61
61
/// <summary>
62
62
/// Creates a <see cref="RequestDelegate"/> implementation for <paramref name="action"/>.
@@ -168,7 +168,7 @@ public static RequestDelegate Create(MethodInfo methodInfo, Func<HttpContext, ob
168
168
169
169
if ( factoryContext . UsingTempSourceString )
170
170
{
171
- responseWritingMethodCall = Expression . Block ( new [ ] { TempSourceStringExpr } , responseWritingMethodCall ) ;
171
+ responseWritingMethodCall = Expression . Block ( new [ ] { TryParseMethodCache . TempSourceStringExpr } , responseWritingMethodCall ) ;
172
172
}
173
173
174
174
return HandleRequestBodyAndCompileRequestDelegate ( responseWritingMethodCall , factoryContext ) ;
@@ -555,7 +555,7 @@ private static Expression BindParameterFromValue(ParameterInfo parameter, Expres
555
555
Expression . IfThen ( Expression . Equal ( argument , Expression . Constant ( null ) ) ,
556
556
Expression . Block (
557
557
Expression . Assign ( WasParamCheckFailureExpr , Expression . Constant ( true ) ) ,
558
- Expression . Call ( LogRequiredParameterNotProvidedMethod ,
558
+ Expression . Call ( LogRequiredParameterNotProvidedMethod ,
559
559
HttpContextExpr , Expression . Constant ( parameter . ParameterType . Name ) , Expression . Constant ( parameter . Name ) )
560
560
)
561
561
)
@@ -643,7 +643,7 @@ private static Expression BindParameterFromValue(ParameterInfo parameter, Expres
643
643
var failBlock = Expression . Block (
644
644
Expression . Assign ( WasParamCheckFailureExpr , Expression . Constant ( true ) ) ,
645
645
Expression . Call ( LogParameterBindingFailureMethod ,
646
- HttpContextExpr , parameterTypeNameConstant , parameterNameConstant , TempSourceStringExpr ) ) ;
646
+ HttpContextExpr , parameterTypeNameConstant , parameterNameConstant , TryParseMethodCache . TempSourceStringExpr ) ) ;
647
647
648
648
var tryParseCall = tryParseMethodCall ( parsedValue ) ;
649
649
@@ -682,14 +682,14 @@ private static Expression BindParameterFromValue(ParameterInfo parameter, Expres
682
682
var fullParamCheckBlock = ! isOptional
683
683
? Expression . Block (
684
684
// tempSourceString = httpContext.RequestValue["id"];
685
- Expression . Assign ( TempSourceStringExpr , valueExpression ) ,
685
+ Expression . Assign ( TryParseMethodCache . TempSourceStringExpr , valueExpression ) ,
686
686
// if (tempSourceString == null) { ... } only produced when parameter is required
687
687
checkRequiredParaseableParameterBlock ,
688
688
// if (tempSourceString != null) { ... }
689
- ifNotNullTryParse )
689
+ ifNotNullTryParse )
690
690
: Expression . Block (
691
691
// tempSourceString = httpContext.RequestValue["id"];
692
- Expression . Assign ( TempSourceStringExpr , valueExpression ) ,
692
+ Expression . Assign ( TryParseMethodCache . TempSourceStringExpr , valueExpression ) ,
693
693
// if (tempSourceString != null) { ... }
694
694
ifNotNullTryParse ) ;
695
695
@@ -737,7 +737,7 @@ private static Expression BindParameterFromBody(ParameterInfo parameter, bool al
737
737
Expression . Equal ( BodyValueExpr , Expression . Constant ( null ) ) ,
738
738
Expression . Block (
739
739
Expression . Assign ( WasParamCheckFailureExpr , Expression . Constant ( true ) ) ,
740
- Expression . Call ( LogRequiredParameterNotProvidedMethod ,
740
+ Expression . Call ( LogRequiredParameterNotProvidedMethod ,
741
741
HttpContextExpr , Expression . Constant ( parameter . ParameterType . Name ) , Expression . Constant ( parameter . Name ) )
742
742
)
743
743
)
@@ -863,8 +863,8 @@ static async Task ExecuteAwaited(Task<string> task, HttpContext httpContext)
863
863
864
864
private static Task ExecuteWriteStringResponseAsync ( HttpContext httpContext , string text )
865
865
{
866
- SetPlaintextContentType ( httpContext ) ;
867
- return httpContext . Response . WriteAsync ( text ) ;
866
+ SetPlaintextContentType ( httpContext ) ;
867
+ return httpContext . Response . WriteAsync ( text ) ;
868
868
}
869
869
870
870
private static Task ExecuteValueTask ( ValueTask task )
0 commit comments