Skip to content

Add support for TryParse(HttpContext, ...) to RequestDelegateFactory #35433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 18, 2021

Conversation

halter73
Copy link
Member

@halter73 halter73 commented Aug 18, 2021

  • This also checks for the new TryParse overload in EndpointMetadataApiDescriptionProvider.cs
  • TryParse(HttpContext, ...) is preferred over TryParse(string, ...) if both are present.
  • This has no support for optionality since there's no way to determine if the parameter is simply missing or invalid
    • As a consequence TryParse(HttpContext, ...) will never be used if the parameter is a nullable struct, but it could fall back to TryParse(string, ...) in this case

@@ -56,8 +59,9 @@ public static partial class RequestDelegateFactory
private static readonly MemberExpression StatusCodeExpr = Expression.Property(HttpResponseExpr, typeof(HttpResponse).GetProperty(nameof(HttpResponse.StatusCode))!);
private static readonly MemberExpression CompletedTaskExpr = Expression.Property(null, (PropertyInfo)GetMemberInfo<Func<Task>>(() => Task.CompletedTask));

private static readonly BinaryExpression TempSourceStringNotNullExpr = Expression.NotEqual(TryParseMethodCache.TempSourceStringExpr, Expression.Constant(null));
private static readonly BinaryExpression TempSourceStringNullExpr = Expression.Equal(TryParseMethodCache.TempSourceStringExpr, Expression.Constant(null));
private static ParameterExpression TempSourceStringExpr => TryParseMethodCache.TempSourceStringExpr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner

Copy link
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@halter73 halter73 merged commit 924b8e8 into main Aug 18, 2021
@halter73 halter73 deleted the halter73/tryparse-httpcontext branch August 18, 2021 03:38
@ghost ghost added this to the 6.0-rc1 milestone Aug 18, 2021
@davidfowl
Copy link
Member

davidfowl commented Aug 18, 2021

Wrong branch @halter73? Or rather, we should also merge this into the release/6.0.0-rc1 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants