From ea7f71e4d974a958e0b46e9728e8915c7f654a6b Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 29 Mar 2023 14:34:00 -0700 Subject: [PATCH 1/7] Update RDG to use interceptors feature --- Directory.Build.props | 1 + eng/Versions.props | 20 +- .../Http.Extensions/gen/GeneratorSteps.cs | 5 +- .../gen/RequestDelegateGenerator.cs | 233 +- .../gen/RequestDelegateGeneratorSources.cs | 98 +- .../Emitters/EmitterConstants.cs | 3 +- .../Emitters/EmitterContext.cs | 3 +- .../Emitters/EmitterExtensions.cs | 3 +- .../Emitters/EndpointEmitter.cs | 219 + .../Emitters/EndpointParameterEmitter.cs | 293 +- .../Emitters/EndpointResponseEmitter.cs | 92 + .../Model/ConstructorParameter.cs | 2 +- .../Model}/Endpoint.cs | 13 +- .../Model}/EndpointDelegateComparer.cs | 2 +- .../Model}/EndpointParameter.cs | 7 +- .../Model}/EndpointParameterSource.cs | 2 +- .../Model}/EndpointResponse.cs | 4 +- .../Model}/InvocationOperationExtensions.cs | 2 +- .../Model/ParameterLookupKey.cs | 2 +- .../Emitters/EndpointEmitter.cs | 132 - .../Emitters/EndpointJsonResponseEmitter.cs | 28 - .../StaticRouteHandlerModel.Emitter.cs | 420 -- ...MapAction_BindAsync_Snapshot.generated.txt | 3513 ++++++++--------- ...Param_ComplexReturn_Snapshot.generated.txt | 338 +- ...Header_ComplexTypeArrayParam.generated.txt | 223 +- ...der_NullableStringArrayParam.generated.txt | 189 +- ...licitHeader_StringArrayParam.generated.txt | 189 +- ...tQuery_ComplexTypeArrayParam.generated.txt | 223 +- ...ery_NullableStringArrayParam.generated.txt | 187 +- ...plicitQuery_StringArrayParam.generated.txt | 187 +- ...eParam_SimpleReturn_Snapshot.generated.txt | 493 ++- ...Source_SimpleReturn_Snapshot.generated.txt | 865 ++-- ...tQuery_ComplexTypeArrayParam.generated.txt | 225 +- ...ery_NullableStringArrayParam.generated.txt | 232 +- ...gArrayParam_EmptyQueryValues.generated.txt | 232 +- ...ngArrayParam_QueryNotPresent.generated.txt | 232 +- ...plicitQuery_StringArrayParam.generated.txt | 232 +- ...ce_HandlesBothJsonAndService.generated.txt | 257 +- ...pecialTypeParam_StringReturn.generated.txt | 181 +- ...ipleStringParam_StringReturn.generated.txt | 245 +- ...aram_StringReturn_WithFilter.generated.txt | 169 +- ...n_ReturnsString_Has_Metadata.generated.txt | 169 +- ...ion_ReturnsTodo_Has_Metadata.generated.txt | 167 +- ...onProblemResult_Has_Metadata.generated.txt | 160 +- ..._ReturnsVoid_Has_No_Metadata.generated.txt | 156 +- ...omplexTypeParam_StringReturn.generated.txt | 229 +- ...SingleEnumParam_StringReturn.generated.txt | 229 +- ...ngValueProvided_StringReturn.generated.txt | 193 +- ...MetadataEmitter_Has_Metadata.generated.txt | 220 +- ...AndBody_ShouldUseQueryString.generated.txt | 238 +- ...AndBody_ShouldUseQueryString.generated.txt | 238 +- ...String_AndBody_ShouldUseBody.generated.txt | 238 +- ...String_AndBody_ShouldUseBody.generated.txt | 238 +- ...String_AndBody_ShouldUseBody.generated.txt | 236 +- ...hArrayQueryString_ShouldFail.generated.txt | 232 +- ...pAction_NoParam_StringReturn.generated.txt | 558 ++- ...tion_WithParams_StringReturn.generated.txt | 465 ++- ...ateValidateGeneratedFormCode.generated.txt | 350 +- .../VerifyAsParametersBaseline.generated.txt | 975 +++-- .../CompileTimeCreationTests.cs | 25 + .../RequestDelegateCreationTestBase.cs | 25 +- .../RequestDelegateCreationTests.Arrays.cs | 2 +- .../RequestDelegateCreationTests.BindAsync.cs | 2 +- .../RequestDelegateCreationTests.Metadata.cs | 2 +- ...stDelegateCreationTests.QueryParameters.cs | 2 +- ...questDelegateCreationTests.SpecialTypes.cs | 2 +- .../RequestDelegateCreationTests.TryParse.cs | 2 +- .../RequestDelegateCreationTests.cs | 12 +- src/Shared/RoslynUtils/CodeWriter.cs | 6 + 69 files changed, 7477 insertions(+), 7890 deletions(-) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler}/Emitters/EmitterConstants.cs (97%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler}/Emitters/EmitterContext.cs (96%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler}/Emitters/EmitterExtensions.cs (95%) create mode 100644 src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler}/Emitters/EndpointParameterEmitter.cs (60%) create mode 100644 src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler}/Model/ConstructorParameter.cs (93%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler/Model}/Endpoint.cs (91%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler/Model}/EndpointDelegateComparer.cs (96%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler/Model}/EndpointParameter.cs (99%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler/Model}/EndpointParameterSource.cs (97%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler/Model}/EndpointResponse.cs (99%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler/Model}/InvocationOperationExtensions.cs (99%) rename src/Http/Http.Extensions/gen/{StaticRouteHandlerModel => StaticRouteHandler}/Model/ParameterLookupKey.cs (97%) delete mode 100644 src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointEmitter.cs delete mode 100644 src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointJsonResponseEmitter.cs delete mode 100644 src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Emitter.cs diff --git a/Directory.Build.props b/Directory.Build.props index e5a2b95bfab1..c2bc06baaa24 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,6 +13,7 @@ true latest Default + /Users/captainsafia/repos/roslyn/artifacts/packages/Release/Shipping diff --git a/eng/Versions.props b/eng/Versions.props index 980e882d5b3c..90c152d133db 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -144,10 +144,10 @@ 8.0.0-preview.6.23312.10 8.0.0-preview.6.23312.10 - 4.4.0-4.22520.2 - 4.4.0-4.22520.2 - 4.4.0-4.22520.2 - 4.4.0-4.22520.2 + 4.7.0-dev + 4.7.0-dev + 4.7.0-dev + 4.7.0-dev 6.2.2 @@ -239,11 +239,13 @@ 3.3.1 - 4.5.0 - 4.4.0-4.22520.2 - 4.4.0-4.22520.2 - 4.4.0-4.22520.2 - 4.4.0-4.22520.2 + 4.7.0-dev + 4.7.0-dev + 4.7.0-dev + 4.7.0-dev + 4.7.0-dev + true + 4.7.0-dev 3.3.3 1.1.2-beta1.22531.1 1.1.2-beta1.22531.1 diff --git a/src/Http/Http.Extensions/gen/GeneratorSteps.cs b/src/Http/Http.Extensions/gen/GeneratorSteps.cs index 2608f97a1ee6..a90776d30178 100644 --- a/src/Http/Http.Extensions/gen/GeneratorSteps.cs +++ b/src/Http/Http.Extensions/gen/GeneratorSteps.cs @@ -5,5 +5,8 @@ namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator; internal class GeneratorSteps { internal const string EndpointModelStep = nameof(EndpointModelStep); - internal const string EndpointsWithoutDiagnosicsStep = nameof(EndpointsWithoutDiagnosicsStep); + internal const string EndpointsWithoutDiagnosticsStep = nameof(EndpointsWithoutDiagnosticsStep); + internal const string EndpointsInterceptorsStep = nameof(EndpointsInterceptorsStep); + internal const string EndpointsHelperMethodsStep = nameof(EndpointsHelperMethodsStep); + internal const string EndpointsHelperTypesStep = nameof(EndpointsHelperTypesStep); } diff --git a/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs b/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs index ca4e7cc17dcd..b8dc95ed6579 100644 --- a/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs +++ b/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs @@ -9,8 +9,8 @@ using Microsoft.AspNetCore.App.Analyzers.Infrastructure; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Operations; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.CodeAnalysis.CSharp; namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator; @@ -53,126 +53,113 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var endpoints = endpointsWithDiagnostics .Where(endpoint => endpoint.Diagnostics.Count == 0) - .WithTrackingName(GeneratorSteps.EndpointsWithoutDiagnosicsStep); - - var thunks = endpoints.Select((endpoint, _) => - { - using var stringWriter = new StringWriter(CultureInfo.InvariantCulture); - using var codeWriter = new CodeWriter(stringWriter, baseIndent: 3); - codeWriter.InitializeIndent(); - codeWriter.WriteLine($"[{endpoint.EmitSourceKey()}] = ("); - codeWriter.Indent++; - codeWriter.WriteLine("(methodInfo, options) =>"); - codeWriter.StartBlock(); - codeWriter.WriteLine(@"Debug.Assert(options != null, ""RequestDelegateFactoryOptions not found."");"); - codeWriter.WriteLine(@"Debug.Assert(options.EndpointBuilder != null, ""EndpointBuilder not found."");"); - codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new SourceKey{endpoint.EmitSourceKey()});"); - endpoint.EmitEndpointMetadataPopulation(codeWriter); - codeWriter.WriteLine("return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() };"); - codeWriter.EndBlockWithComma(); - codeWriter.WriteLine("(del, options, inferredMetadataResult) =>"); - codeWriter.StartBlock(); - codeWriter.WriteLine(@"Debug.Assert(options != null, ""RequestDelegateFactoryOptions not found."");"); - codeWriter.WriteLine(@"Debug.Assert(options.EndpointBuilder != null, ""EndpointBuilder not found."");"); - codeWriter.WriteLine(@"Debug.Assert(options.EndpointBuilder.ApplicationServices != null, ""ApplicationServices not found."");"); - codeWriter.WriteLine(@"Debug.Assert(options.EndpointBuilder.FilterFactories != null, ""FilterFactories not found."");"); - codeWriter.WriteLine($"var handler = ({endpoint.EmitHandlerDelegateType(considerOptionality: true)})del;"); - codeWriter.WriteLine("EndpointFilterDelegate? filteredInvocation = null;"); - if (endpoint.EmitterContext.RequiresLoggingHelper || endpoint.EmitterContext.HasJsonBodyOrService || endpoint.Response?.IsSerializableJsonResponse(out var _) is true) - { - codeWriter.WriteLine("var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices;"); - } - endpoint.EmitLoggingPreamble(codeWriter); - endpoint.EmitRouteOrQueryResolver(codeWriter); - endpoint.EmitJsonBodyOrServiceResolver(codeWriter); - endpoint.Response?.EmitJsonPreparation(codeWriter); - if (endpoint.NeedsParameterArray) - { - codeWriter.WriteLine("var parameters = del.Method.GetParameters();"); - } - codeWriter.WriteLineNoTabs(string.Empty); - codeWriter.WriteLine("if (options.EndpointBuilder.FilterFactories.Count > 0)"); - codeWriter.StartBlock(); - codeWriter.WriteLine(endpoint.Response?.IsAwaitable == true - ? "filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(async ic =>" - : "filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic =>"); - codeWriter.StartBlock(); - codeWriter.WriteLine("if (ic.HttpContext.Response.StatusCode == 400)"); - codeWriter.StartBlock(); - codeWriter.WriteLine(endpoint.Response?.IsAwaitable == true - ? "return (object?)Results.Empty;" - : "return ValueTask.FromResult(Results.Empty);"); - codeWriter.EndBlock(); - endpoint.EmitFilteredInvocation(codeWriter); - codeWriter.EndBlockWithComma(); - codeWriter.WriteLine("options.EndpointBuilder,"); - codeWriter.WriteLine("handler.Method);"); - codeWriter.EndBlock(); - codeWriter.WriteLineNoTabs(string.Empty); - endpoint.EmitRequestHandler(codeWriter); - codeWriter.WriteLineNoTabs(string.Empty); - endpoint.EmitFilteredRequestHandler(codeWriter); - codeWriter.WriteLineNoTabs(string.Empty); - codeWriter.WriteLine("RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered;"); - codeWriter.WriteLine("var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty;"); - codeWriter.WriteLine("return new RequestDelegateResult(targetDelegate, metadata);"); - codeWriter.Indent--; - codeWriter.Write("}),"); - return stringWriter.ToString(); - }); + .WithTrackingName(GeneratorSteps.EndpointsWithoutDiagnosticsStep); var stronglyTypedEndpointDefinitions = endpoints - .Collect() - .Select((endpoints, _) => + .Select((endpoint, _) => { - var dedupedByDelegate = endpoints.Distinct(EndpointDelegateComparer.Instance); using var stringWriter = new StringWriter(CultureInfo.InvariantCulture); using var codeWriter = new CodeWriter(stringWriter, baseIndent: 2); - foreach (var endpoint in dedupedByDelegate) + codeWriter.WriteLine($$"""[global::System.Runtime.CompilerServices.InterceptsLocation(@"{{endpoint!.Location.File}}", {{endpoint.Location.LineNumber}}, {{endpoint.Location.CharaceterNumber + 1}})]"""); + codeWriter.WriteLine($"internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder {endpoint!.HttpMethod}_{endpoint.Location.LineNumber}("); + codeWriter.Indent++; + codeWriter.WriteLine("this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints,"); + // MapFallback overloads that only take a delegate do not need a pattern argument + if (endpoint.HttpMethod != "MapFallback" || endpoint.Operation.Arguments.Length != 2) + { + codeWriter.WriteLine(@"[global::System.Diagnostics.CodeAnalysis.StringSyntax(""Route"")] string pattern,"); + } + // MapMethods overloads define an additional `httpMethods` parameter + if (endpoint.HttpMethod == "MapMethods") { - codeWriter.WriteLine($"internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder {endpoint.HttpMethod}("); - codeWriter.Indent++; - codeWriter.WriteLine("this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints,"); - // MapFallback overloads that only take a delegate do not need a pattern argument - if (endpoint.HttpMethod != "MapFallback" || endpoint.Operation.Arguments.Length != 2) - { - codeWriter.WriteLine(@"[global::System.Diagnostics.CodeAnalysis.StringSyntax(""Route"")] string pattern,"); - } - // MapMethods overloads define an additional `httpMethods` parameter - if (endpoint.HttpMethod == "MapMethods") - { - codeWriter.WriteLine("global::System.Collections.Generic.IEnumerable httpMethods,"); - } - codeWriter.WriteLine($"global::{endpoint.EmitHandlerDelegateType()} handler,"); - codeWriter.WriteLine(@"[global::System.Runtime.CompilerServices.CallerFilePath] string filePath = """","); - codeWriter.WriteLine("[global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0)"); - codeWriter.Indent--; - codeWriter.StartBlock(); - codeWriter.WriteLine("return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore("); - codeWriter.Indent++; - codeWriter.WriteLine("endpoints,"); - // For `MapFallback` overloads that only take a delegate, provide the assumed default - // Otherwise, pass the pattern provided from the MapX invocation - if (endpoint.HttpMethod != "MapFallback" && endpoint.Operation.Arguments.Length != 2) - { - codeWriter.WriteLine("pattern,"); - } - else - { - codeWriter.WriteLine($"{SymbolDisplay.FormatLiteral("{*path:nonfile}", true)},"); - } - codeWriter.WriteLine("handler,"); - codeWriter.WriteLine($"{endpoint.EmitVerb()},"); - codeWriter.WriteLine("filePath,"); - codeWriter.WriteLine("lineNumber);"); - codeWriter.Indent--; - codeWriter.EndBlock(); + codeWriter.WriteLine("global::System.Collections.Generic.IEnumerable httpMethods,"); } + codeWriter.WriteLine($"global::System.Delegate handler)"); + codeWriter.Indent--; + codeWriter.StartBlock(); + codeWriter.WriteLine("MetadataPopulator populateMetadata = (methodInfo, options) =>"); + codeWriter.StartBlock(); + codeWriter.WriteLine(@"Debug.Assert(options != null, ""RequestDelegateFactoryOptions not found."");"); + codeWriter.WriteLine(@"Debug.Assert(options.EndpointBuilder != null, ""EndpointBuilder not found."");"); + codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new SourceKey{endpoint.EmitSourceKey()});"); + endpoint.EmitEndpointMetadataPopulation(codeWriter); + codeWriter.WriteLine("return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() };"); + codeWriter.EndBlockWithSemicolon(); + + codeWriter.WriteLine("RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) =>"); + codeWriter.StartBlock(); + codeWriter.WriteLine(@"Debug.Assert(options != null, ""RequestDelegateFactoryOptions not found."");"); + codeWriter.WriteLine(@"Debug.Assert(options.EndpointBuilder != null, ""EndpointBuilder not found."");"); + codeWriter.WriteLine(@"Debug.Assert(options.EndpointBuilder.ApplicationServices != null, ""ApplicationServices not found."");"); + codeWriter.WriteLine(@"Debug.Assert(options.EndpointBuilder.FilterFactories != null, ""FilterFactories not found."");"); + codeWriter.WriteLine($"var handler = Cast(del, {endpoint.EmitHandlerDelegateType(considerOptionality: true)} => throw null!);"); + codeWriter.WriteLine("EndpointFilterDelegate? filteredInvocation = null;"); + codeWriter.WriteLine("if (options.EndpointBuilder.FilterFactories.Count > 0)"); + codeWriter.StartBlock(); + codeWriter.WriteLine(endpoint.Response?.IsAwaitable == true + ? "filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(async ic =>" + : "filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic =>"); + codeWriter.StartBlock(); + codeWriter.WriteLine("if (ic.HttpContext.Response.StatusCode == 400)"); + codeWriter.StartBlock(); + codeWriter.WriteLine(endpoint.Response?.IsAwaitable == true + ? "return (object?)Results.Empty;" + : "return ValueTask.FromResult(Results.Empty);"); + codeWriter.EndBlock(); + endpoint.EmitFilteredInvocation(codeWriter); + codeWriter.EndBlockWithComma(); + codeWriter.WriteLine("options.EndpointBuilder,"); + codeWriter.WriteLine("handler.Method);"); + codeWriter.EndBlock(); + codeWriter.WriteLineNoTabs(string.Empty); + + if (endpoint.EmitterContext.RequiresLoggingHelper || endpoint.EmitterContext.HasJsonBodyOrService || endpoint.Response?.IsSerializableJsonResponse(out var _) is true) + { + codeWriter.WriteLine("var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices;"); + } + endpoint.EmitLoggingPreamble(codeWriter); + endpoint.EmitRouteOrQueryResolver(codeWriter); + endpoint.EmitJsonBodyOrServiceResolver(codeWriter); + endpoint.Response?.EmitJsonPreparation(codeWriter); + if (endpoint.NeedsParameterArray) + { + codeWriter.WriteLine("var parameters = del.Method.GetParameters();"); + } + codeWriter.WriteLineNoTabs(string.Empty); + endpoint.EmitRequestHandler(codeWriter); + codeWriter.WriteLineNoTabs(string.Empty); + endpoint.EmitFilteredRequestHandler(codeWriter); + codeWriter.WriteLineNoTabs(string.Empty); + codeWriter.WriteLine("RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered;"); + codeWriter.WriteLine("var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty;"); + codeWriter.WriteLine("return new RequestDelegateResult(targetDelegate, metadata);"); + codeWriter.EndBlockWithSemicolon(); + + codeWriter.WriteLine("return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore("); + codeWriter.Indent++; + codeWriter.WriteLine("endpoints,"); + // For `MapFallback` overloads that only take a delegate, provide the assumed default + // Otherwise, pass the pattern provided from the MapX invocation + if (endpoint.HttpMethod != "MapFallback" && endpoint.Operation.Arguments.Length != 2) + { + codeWriter.WriteLine("pattern,"); + } + else + { + codeWriter.WriteLine($"{SymbolDisplay.FormatLiteral("{*path:nonfile}", true)},"); + } + codeWriter.WriteLine("handler,"); + codeWriter.WriteLine($"{endpoint!.EmitVerb()},"); + codeWriter.WriteLine("populateMetadata,"); + codeWriter.WriteLine($"createRequestDelegate);"); + codeWriter.Indent--; + codeWriter.EndBlock(); return stringWriter.ToString(); - }); + }) + .WithTrackingName(GeneratorSteps.EndpointsInterceptorsStep); - var endpointHelpers = endpoints + var helperMethods = endpoints .Collect() .Select((endpoints, _) => { @@ -242,7 +229,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context) } return stringWriter.ToString(); - }); + }) + .WithTrackingName(GeneratorSteps.EndpointsHelperMethodsStep); var helperTypes = endpoints .Collect() @@ -277,29 +265,28 @@ public void Initialize(IncrementalGeneratorInitializationContext context) } return stringWriter.ToString(); - }); + }) + .WithTrackingName(GeneratorSteps.EndpointsHelperTypesStep); - var thunksAndEndpoints = thunks.Collect().Combine(stronglyTypedEndpointDefinitions).Combine(endpointHelpers).Combine(helperTypes); + var thunksAndEndpoints = stronglyTypedEndpointDefinitions.Collect().Combine(helperMethods).Combine(helperTypes); context.RegisterSourceOutput(thunksAndEndpoints, (context, sources) => { - var (((thunks, endpointsCode), helperMethods), helperTypes) = sources; + var ((endpointsCode, helperMethods), helperTypes) = sources; - if (thunks.IsDefaultOrEmpty || string.IsNullOrEmpty(endpointsCode)) + if (endpointsCode.IsDefaultOrEmpty) { return; } - var thunksCode = new StringBuilder(); - foreach (var thunk in thunks) + var endpoints = new StringBuilder(); + foreach (var thunk in endpointsCode) { - thunksCode.AppendLine(thunk); + endpoints.AppendLine(thunk); } var code = RequestDelegateGeneratorSources.GetGeneratedRouteBuilderExtensionsSource( - genericThunks: string.Empty, - thunks: thunksCode.ToString(), - endpoints: endpointsCode, + endpoints: endpoints.ToString(), helperMethods: helperMethods ?? string.Empty, helperTypes: helperTypes ?? string.Empty); diff --git a/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs b/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs index 699b9421e269..cbe395f478cb 100644 --- a/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs +++ b/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs @@ -500,7 +500,7 @@ public override bool IsDefined(Type attributeType, bool inherit) } """; - public static string GetGeneratedRouteBuilderExtensionsSource(string genericThunks, string thunks, string endpoints, string helperMethods, string helperTypes) => $$""" + public static string GetGeneratedRouteBuilderExtensionsSource(string endpoints, string helperMethods, string helperTypes) => $$""" {{SourceHeader}} namespace Microsoft.AspNetCore.Builder @@ -517,8 +517,18 @@ public SourceKey(string path, int line) Line = line; } } +} -{{GetEndpoints(endpoints)}} +namespace System.Runtime.CompilerServices +{ + {{GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + } + } } namespace Microsoft.AspNetCore.Http.Generated @@ -554,8 +564,29 @@ namespace Microsoft.AspNetCore.Http.Generated {{GeneratedCodeAttribute}} file static class GeneratedRouteBuilderExtensionsCore { -{{GetGenericThunks(genericThunks)}} -{{GetThunks(thunks)}} + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + {{endpoints}} + + internal static RouteHandlerBuilder MapCore( + this IEndpointRouteBuilder routes, + string pattern, + Delegate handler, + IEnumerable? httpMethods, + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) + { + return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); + } + + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { @@ -600,63 +631,4 @@ private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) {{LogOrThrowExceptionHelperClass}} } """; - private static string GetGenericThunks(string genericThunks) => genericThunks != string.Empty ? $$""" - private static class GenericThunks - { - public static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { - {{genericThunks}} - }; - } - - internal static RouteHandlerBuilder MapCore( - this IEndpointRouteBuilder routes, - string pattern, - Delegate handler, - IEnumerable httpMethods, - string filePath, - int lineNumber) - { - var (populateMetadata, createRequestDelegate) = GenericThunks.map[(filePath, lineNumber)]; - return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); - } -""" : string.Empty; - - private static string GetThunks(string thunks) => thunks != string.Empty ? $$""" - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { -{{thunks}} - }; - - internal static RouteHandlerBuilder MapCore( - this IEndpointRouteBuilder routes, - string pattern, - Delegate handler, - IEnumerable? httpMethods, - string filePath, - int lineNumber) - { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; - return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); - } -""" : string.Empty; - - private static string GetEndpoints(string endpoints) => endpoints != string.Empty ? $$""" - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. - {{GeneratedCodeAttribute}} - internal static class GenerateRouteBuilderEndpoints - { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - {{endpoints}} - } -""" : string.Empty; } diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterConstants.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterConstants.cs similarity index 97% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterConstants.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterConstants.cs index f609f825a44a..e6ee10bad40a 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterConstants.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterConstants.cs @@ -1,7 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.CodeAnalysis; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; + +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; internal static class EmitterConstants { diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterContext.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterContext.cs similarity index 96% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterContext.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterContext.cs index 669df4470d4e..4957e0cc09c1 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterContext.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterContext.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; + +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; internal sealed class EmitterContext { diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterExtensions.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterExtensions.cs similarity index 95% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterExtensions.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterExtensions.cs index b17e0614f2a6..ea21fa082555 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterExtensions.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterExtensions.cs @@ -3,9 +3,10 @@ using System; using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Analyzers.Infrastructure; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.CodeAnalysis; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; internal static class EmitterExtensions { diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs new file mode 100644 index 000000000000..bed29c7def55 --- /dev/null +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs @@ -0,0 +1,219 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using Microsoft.CodeAnalysis; +using System.Linq; +using System.Text; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; + +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; + +internal static class EndpointEmitter +{ + public static string EmitHandlerDelegateType(this Endpoint endpoint, bool considerOptionality = false) + { + // Emits a delegate type to use when casting the input that captures + // default parameter values. + // + // void (int arg0, Todo arg1) => throw null! + // IResult (int arg0, Todo arg1) => throw null! + if (endpoint.Parameters.Length == 0) + { + return endpoint.Response == null || (endpoint.Response.HasNoResponse && !endpoint.Response.IsAwaitable) ? "void ()" : $"{endpoint.Response.WrappedResponseType} ()"; + } + var parameterTypeList = string.Join(", ", endpoint.Parameters.Select((p, i) => $"{getType(p, considerOptionality)} arg{i}{(p.HasDefaultValue ? $"= {p.DefaultValue}" : string.Empty)}")); + + if (endpoint.Response == null || (endpoint.Response.HasNoResponse && !endpoint.Response.IsAwaitable)) + { + return $"void ({parameterTypeList})"; + } + return $"{endpoint.Response.WrappedResponseType} ({parameterTypeList})"; + + static string getType(EndpointParameter p, bool considerOptionality) + { + return considerOptionality + ? p.Type.ToDisplayString(p.IsOptional ? NullableFlowState.MaybeNull : NullableFlowState.NotNull, EmitterConstants.DisplayFormat) + : p.Type.ToDisplayString(EmitterConstants.DisplayFormat); + } + } + + public static string EmitSourceKey(this Endpoint endpoint) + { + return $@"(@""{endpoint.Location.File}"", {endpoint.Location.LineNumber})"; + } + + public static string EmitVerb(this Endpoint endpoint) + { + return endpoint.HttpMethod switch + { + "MapGet" => "GetVerb", + "MapPut" => "PutVerb", + "MapPost" => "PostVerb", + "MapDelete" => "DeleteVerb", + "MapPatch" => "PatchVerb", + "MapMethods" => "httpMethods", + "Map" => "null", + "MapFallback" => "null", + _ => throw new ArgumentException($"Received unexpected HTTP method: {endpoint.HttpMethod}") + }; + } + + /* + * Emit invocation to the request handler. The structure + * involved here consists of a call to bind parameters, check + * their validity (optionality), invoke the underlying handler with + * the arguments bound from HTTP context, and write out the response. + */ + public static void EmitRequestHandler(this Endpoint endpoint, CodeWriter codeWriter) + { + codeWriter.WriteLine(endpoint.IsAwaitable ? "async Task RequestHandler(HttpContext httpContext)" : "Task RequestHandler(HttpContext httpContext)"); + codeWriter.StartBlock(); // Start handler method block + codeWriter.WriteLine("var wasParamCheckFailure = false;"); + + if (endpoint.Parameters.Length > 0) + { + codeWriter.WriteLine(endpoint.Parameters.EmitParameterPreparation(endpoint.EmitterContext, codeWriter.Indent)); + } + + codeWriter.WriteLine("if (wasParamCheckFailure)"); + codeWriter.StartBlock(); // Start if-statement block + codeWriter.WriteLine("httpContext.Response.StatusCode = 400;"); + codeWriter.WriteLine(endpoint.IsAwaitable ? "return;" : "return Task.CompletedTask;"); + codeWriter.EndBlock(); // End if-statement block + if (endpoint.Response == null) + { + return; + } + if (!endpoint.Response.HasNoResponse && endpoint.Response is { ContentType: { } contentType }) + { + codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""{contentType}"";"); + } + if (!endpoint.Response.HasNoResponse) + { + codeWriter.Write("var result = "); + } + if (endpoint.Response.IsAwaitable) + { + codeWriter.Write("await "); + } + codeWriter.WriteLine($"handler({endpoint.EmitArgumentList()});"); + if (!endpoint.Response.HasNoResponse) + { + codeWriter.WriteLine(endpoint.Response.EmitResponseWritingCall(endpoint.IsAwaitable)); + } + else if (!endpoint.IsAwaitable) + { + codeWriter.WriteLine("return Task.CompletedTask;"); + } + codeWriter.EndBlock(); // End handler method block + } + + public static void EmitFilteredRequestHandler(this Endpoint endpoint, CodeWriter codeWriter) + { + var argumentList = endpoint.Parameters.Length == 0 ? string.Empty : $", {endpoint.EmitArgumentList()}"; + var invocationCreator = endpoint.Parameters.Length > 8 + ? "new DefaultEndpointFilterInvocationContext" + : "EndpointFilterInvocationContext.Create"; + var invocationGenericArgs = endpoint.Parameters.Length is > 0 and < 8 + ? $"<{endpoint.EmitFilterInvocationContextTypeArgs()}>" + : string.Empty; + + codeWriter.WriteLine("async Task RequestHandlerFiltered(HttpContext httpContext)"); + codeWriter.StartBlock(); // Start handler method block + codeWriter.WriteLine("var wasParamCheckFailure = false;"); + + if (endpoint.Parameters.Length > 0) + { + codeWriter.WriteLine(endpoint.Parameters.EmitParameterPreparation(endpoint.EmitterContext, codeWriter.Indent)); + } + + codeWriter.WriteLine("if (wasParamCheckFailure)"); + codeWriter.StartBlock(); // Start if-statement block + codeWriter.WriteLine("httpContext.Response.StatusCode = 400;"); + codeWriter.EndBlock(); // End if-statement block + codeWriter.WriteLine($"var result = await filteredInvocation({invocationCreator}{invocationGenericArgs}(httpContext{argumentList}));"); + codeWriter.WriteLine("await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext);"); + codeWriter.EndBlock(); // End handler method block + } + + public static void EmitEndpointMetadataPopulation(this Endpoint endpoint, CodeWriter codeWriter) + { + endpoint.EmitAcceptsMetadata(codeWriter); + endpoint.EmitBuiltinResponseTypeMetadata(codeWriter); + endpoint.EmitCallsToMetadataProvidersForParameters(codeWriter); + endpoint.EmitCallToMetadataProviderForResponse(codeWriter); + } + + public static void EmitFilteredInvocation(this Endpoint endpoint, CodeWriter codeWriter) + { + if (endpoint.Response?.HasNoResponse == true) + { + codeWriter.WriteLine(endpoint.Response?.IsAwaitable == true + ? $"await handler({endpoint.EmitFilteredArgumentList()});" + : $"handler({endpoint.EmitFilteredArgumentList()});"); + codeWriter.WriteLine(endpoint.Response?.IsAwaitable == true + ? "return (object?)Results.Empty;" + : "return ValueTask.FromResult(Results.Empty);"); + } + else if (endpoint.Response?.IsAwaitable == true) + { + codeWriter.WriteLine($"var result = await handler({endpoint.EmitFilteredArgumentList()});"); + codeWriter.WriteLine("return (object?)result;"); + } + else + { + codeWriter.WriteLine($"return ValueTask.FromResult(handler({endpoint.EmitFilteredArgumentList()}));"); + } + } + + private static string EmitFilteredArgumentList(this Endpoint endpoint) + { + if (endpoint.Parameters.Length == 0) + { + return string.Empty; + } + + var sb = new StringBuilder(); + + for (var i = 0; i < endpoint.Parameters.Length; i++) + { + // The null suppression operator on the GetArgument(...) call here is required because we'll occassionally be + // dealing with nullable types here. We could try to do fancy things to branch the logic here depending on + // the nullability, but at the end of the day we are going to call GetArguments(...) - at runtime the nullability + // suppression operator doesn't come into play - so its not worth worrying about. + sb.Append($"ic.GetArgument<{endpoint.Parameters[i].Type.ToDisplayString(EmitterConstants.DisplayFormat)}>({i})!"); + + if (i < endpoint.Parameters.Length - 1) + { + sb.Append(", "); + } + } + + return sb.ToString(); + } + + private static string EmitFilterInvocationContextTypeArgs(this Endpoint endpoint) + { + if (endpoint.Parameters.Length == 0) + { + return string.Empty; + } + + var sb = new StringBuilder(); + + for (var i = 0; i < endpoint.Parameters.Length; i++) + { + sb.Append(endpoint.Parameters[i].Type.ToDisplayString(endpoint.Parameters[i].IsOptional ? NullableFlowState.MaybeNull : NullableFlowState.NotNull, EmitterConstants.DisplayFormat)); + + if (i < endpoint.Parameters.Length - 1) + { + sb.Append(", "); + } + } + + return sb.ToString(); + } + + private static string EmitArgumentList(this Endpoint endpoint) => string.Join(", ", endpoint.Parameters.Select(p => p.EmitArgument())); +} diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointParameterEmitter.cs similarity index 60% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointParameterEmitter.cs index 8eec1bda9909..e491cc36cb01 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointParameterEmitter.cs @@ -2,19 +2,147 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; using Microsoft.AspNetCore.Analyzers.Infrastructure; using Microsoft.AspNetCore.Analyzers.RouteEmbeddedLanguage.Infrastructure; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; internal static class EndpointParameterEmitter { - internal static void EmitSpecialParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) + /* + * Iterates through all of the provided parameters + * in a given endpoint and invokes the appropriate + * emission sub-function based on the parameter type. + */ + public static string EmitParameterPreparation(this IEnumerable endpointParameters, EmitterContext emitterContext, int baseIndent = 0) + { + using var stringWriter = new StringWriter(CultureInfo.InvariantCulture); + using var parameterPreparationBuilder = new CodeWriter(stringWriter, baseIndent); + var readFormEmitted = false; + + foreach (var parameter in endpointParameters) + { + switch (parameter.Source) + { + case EndpointParameterSource.SpecialType: + parameter.EmitSpecialParameterPreparation(parameterPreparationBuilder); + break; + case EndpointParameterSource.Query: + case EndpointParameterSource.Header: + parameter.EmitQueryOrHeaderParameterPreparation(parameterPreparationBuilder); + break; + case EndpointParameterSource.Route: + parameter.EmitRouteParameterPreparation(parameterPreparationBuilder); + break; + case EndpointParameterSource.RouteOrQuery: + emitterContext.HasRouteOrQuery = true; + parameter.EmitRouteOrQueryParameterPreparation(parameterPreparationBuilder); + break; + case EndpointParameterSource.BindAsync: + emitterContext.HasBindAsync = true; + parameter.EmitBindAsyncPreparation(parameterPreparationBuilder); + break; + case EndpointParameterSource.JsonBody: + parameter.EmitJsonBodyParameterPreparationString(parameterPreparationBuilder); + break; + case EndpointParameterSource.FormBody: + parameter.EmitFormParameterPreparation(parameterPreparationBuilder, ref readFormEmitted); + break; + case EndpointParameterSource.JsonBodyOrService: + parameter.EmitJsonBodyOrServiceParameterPreparationString(parameterPreparationBuilder); + break; + case EndpointParameterSource.JsonBodyOrQuery: + parameter.EmitJsonBodyOrQueryParameterPreparationString(parameterPreparationBuilder); + break; + case EndpointParameterSource.Service: + parameter.EmitServiceParameterPreparation(parameterPreparationBuilder); + break; + case EndpointParameterSource.AsParameters: + parameter.EmitAsParametersParameterPreparation(parameterPreparationBuilder, emitterContext); + break; + } + } + + return stringWriter.ToString(); + } + + /* + * Emits resolvers that are invoked once at startup + * for initializing how parameters that are ambiguous + * at compile-time should be resolved. + */ + public static void EmitRouteOrQueryResolver(this Endpoint endpoint, CodeWriter codeWriter) + { + foreach (var parameter in endpoint.Parameters) + { + ProcessParameter(parameter, codeWriter, endpoint); + if (parameter is { Source: EndpointParameterSource.AsParameters, EndpointParameters: {} innerParameters }) + { + foreach (var innerParameter in innerParameters) + { + ProcessParameter(innerParameter, codeWriter, endpoint); + } + } + } + + static void ProcessParameter(EndpointParameter parameter, CodeWriter codeWriter, Endpoint endpoint) + { + if (parameter.Source == EndpointParameterSource.RouteOrQuery) + { + var parameterName = parameter.SymbolName; + codeWriter.Write($@"var {parameterName}_RouteOrQueryResolver = "); + codeWriter.WriteLine($@"GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery(""{parameterName}"", options?.RouteParameterNames);"); + endpoint.EmitterContext.HasRouteOrQuery = true; + } + } + } + + public static void EmitJsonBodyOrServiceResolver(this Endpoint endpoint, CodeWriter codeWriter) + { + var serviceProviderEmitted = false; + foreach (var parameter in endpoint.Parameters) + { + ProcessParameter(parameter, codeWriter, ref serviceProviderEmitted); + if (parameter is { Source: EndpointParameterSource.AsParameters, EndpointParameters: {} innerParameters }) + { + foreach (var innerParameter in innerParameters) + { + ProcessParameter(innerParameter, codeWriter, ref serviceProviderEmitted); + } + } + } + + static void ProcessParameter(EndpointParameter parameter, CodeWriter codeWriter, ref bool serviceProviderEmitted) + { + if (parameter.Source == EndpointParameterSource.JsonBodyOrService) + { + if (!serviceProviderEmitted) + { + codeWriter.WriteLine("var serviceProviderIsService = serviceProvider?.GetService();"); + serviceProviderEmitted = true; + } + codeWriter.Write($@"var {parameter.SymbolName}_JsonBodyOrServiceResolver = "); + var shortParameterTypeName = parameter.Type.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat); + codeWriter.WriteLine($"ResolveJsonBodyOrService<{parameter.Type.ToDisplayString(EmitterConstants.DisplayFormat)}>(logOrThrowExceptionHelper, {SymbolDisplay.FormatLiteral(shortParameterTypeName, true)}, {SymbolDisplay.FormatLiteral(parameter.SymbolName, true)}, serviceProviderIsService);"); + } + } + } + + /* + * Emits parameter preparation for a parameter + * of a given source. + */ + private static void EmitSpecialParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) => codeWriter.WriteLine($"var {endpointParameter.EmitHandlerArgument()} = {endpointParameter.AssigningCode};"); - internal static void EmitQueryOrHeaderParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitQueryOrHeaderParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) { codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); @@ -52,7 +180,7 @@ internal static void EmitQueryOrHeaderParameterPreparation(this EndpointParamete endpointParameter.EmitParsingBlock(codeWriter); } - internal static void EmitFormParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter, ref bool readFormEmitted) + private static void EmitFormParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter, ref bool readFormEmitted) { codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); @@ -87,7 +215,7 @@ internal static void EmitFormParameterPreparation(this EndpointParameter endpoin endpointParameter.EmitParsingBlock(codeWriter); } - internal static void EmitParsingBlock(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitParsingBlock(this EndpointParameter endpointParameter, CodeWriter codeWriter) { if (endpointParameter.IsArray && endpointParameter.IsParsable) { @@ -124,7 +252,7 @@ internal static void EmitParsingBlock(this EndpointParameter endpointParameter, } } - internal static void EmitRouteParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitRouteParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) { codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); @@ -151,7 +279,7 @@ internal static void EmitRouteParameterPreparation(this EndpointParameter endpoi endpointParameter.EmitParsingBlock(codeWriter); } - internal static void EmitRouteOrQueryParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitRouteOrQueryParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) { codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); @@ -182,7 +310,7 @@ internal static void EmitRouteOrQueryParameterPreparation(this EndpointParameter endpointParameter.EmitParsingBlock(codeWriter); } - internal static void EmitJsonBodyParameterPreparationString(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitJsonBodyParameterPreparationString(this EndpointParameter endpointParameter, CodeWriter codeWriter) { // Preamble for diagnostics purposes. codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); @@ -204,7 +332,7 @@ internal static void EmitJsonBodyParameterPreparationString(this EndpointParamet codeWriter.EndBlock(); } - internal static void EmitJsonBodyOrServiceParameterPreparationString(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitJsonBodyOrServiceParameterPreparationString(this EndpointParameter endpointParameter, CodeWriter codeWriter) { // Preamble for diagnostics purposes. codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); @@ -225,7 +353,7 @@ internal static void EmitJsonBodyOrServiceParameterPreparationString(this Endpoi codeWriter.EndBlock(); } - internal static void EmitJsonBodyOrQueryParameterPreparationString(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitJsonBodyOrQueryParameterPreparationString(this EndpointParameter endpointParameter, CodeWriter codeWriter) { // Preamble for diagnostics purposes. codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); @@ -260,7 +388,7 @@ internal static void EmitJsonBodyOrQueryParameterPreparationString(this Endpoint codeWriter.EndBlock(); } - internal static void EmitBindAsyncPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitBindAsyncPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) { // Invoke the `BindAsync` method on an interface if it is the target receiver. var receiverType = endpointParameter.BindableMethodSymbol?.ReceiverType is { TypeKind: TypeKind.Interface } targetType @@ -312,7 +440,7 @@ internal static void EmitBindAsyncPreparation(this EndpointParameter endpointPar } } - internal static void EmitServiceParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) + private static void EmitServiceParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter) { codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); @@ -326,17 +454,156 @@ internal static void EmitServiceParameterPreparation(this EndpointParameter endp codeWriter.WriteLine($"var {endpointParameter.EmitHandlerArgument()} = {assigningCode};"); } - internal static void EmitAsParametersParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter, EmitterContext emitterContext) + private static void EmitAsParametersParameterPreparation(this EndpointParameter endpointParameter, CodeWriter codeWriter, EmitterContext emitterContext) { codeWriter.WriteLine(endpointParameter.EmitParameterDiagnosticComment()); codeWriter.WriteLine(endpointParameter.EndpointParameters?.EmitParameterPreparation(baseIndent: codeWriter.Indent, emitterContext: emitterContext)); codeWriter.WriteLine($"var {endpointParameter.EmitHandlerArgument()} = {endpointParameter.AssigningCode};"); } + /* + * Emitters for metadata-related aspects of parameters, such as invoking + * IEndpointParameterMetadataProviders, annotating metadata for form + * and JSON content types, and so on. + */ + public static void EmitCallsToMetadataProvidersForParameters(this Endpoint endpoint, CodeWriter codeWriter) + { + if (endpoint.EmitterContext.HasEndpointParameterMetadataProvider) + { + codeWriter.WriteLine("var parameterInfos = methodInfo.GetParameters();"); + } + + foreach (var parameter in endpoint.Parameters) + { + if (parameter is { Source: EndpointParameterSource.AsParameters, EndpointParameters: { } innerParameters }) + { + foreach (var innerParameter in innerParameters) + { + ProcessParameter(innerParameter, codeWriter); + } + } + else + { + ProcessParameter(parameter, codeWriter); + } + } + + static void ProcessParameter(EndpointParameter parameter, CodeWriter codeWriter) + { + if (parameter.Type is not { } parameterType) + { + return; + } + + if (parameter.IsEndpointParameterMetadataProvider) + { + var resolveParameterInfo = parameter.IsProperty + ? parameter.PropertyAsParameterInfoConstruction + : $"parameterInfos[{parameter.Ordinal}]"; + codeWriter.WriteLine($"var {parameter.SymbolName}_ParameterInfo = {resolveParameterInfo};"); + codeWriter.WriteLine($"PopulateMetadataForParameter<{parameterType.ToDisplayString(EmitterConstants.DisplayFormat)}>({parameter.SymbolName}_ParameterInfo, options.EndpointBuilder);"); + } + + if (parameter.IsEndpointMetadataProvider) + { + codeWriter.WriteLine($"PopulateMetadataForEndpoint<{parameterType.ToDisplayString(EmitterConstants.DisplayFormat)}>(methodInfo, options.EndpointBuilder);"); + } + + } + } + + private static void EmitFormAcceptsMetadata(this Endpoint endpoint, CodeWriter codeWriter) + { + var hasFormFiles = endpoint.Parameters.Any(p => p.IsFormFile); + + if (hasFormFiles) + { + codeWriter.WriteLine("options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.FormFileContentType));"); + } + else + { + codeWriter.WriteLine("options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.FormContentType));"); + } + } + + private static void EmitJsonAcceptsMetadata(this Endpoint endpoint, CodeWriter codeWriter) + { + EndpointParameter? explicitBodyParameter = null; + var potentialImplicitBodyParameters = new List(); + + foreach (var parameter in endpoint.Parameters) + { + if (explicitBodyParameter == null && parameter.Source == EndpointParameterSource.JsonBody) + { + explicitBodyParameter = parameter; + break; + } + else if (parameter.Source == EndpointParameterSource.JsonBodyOrService) + { + potentialImplicitBodyParameters.Add(parameter); + } + } + + if (explicitBodyParameter != null) + { + codeWriter.WriteLine($$"""options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof({{explicitBodyParameter.Type.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability)}}), isOptional: {{(explicitBodyParameter.IsOptional ? "true" : "false")}}, contentTypes: GeneratedMetadataConstants.JsonContentType));"""); + } + else if (potentialImplicitBodyParameters.Count > 0) + { + codeWriter.WriteLine("var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices;"); + codeWriter.WriteLine($"var serviceProviderIsService = serviceProvider.GetRequiredService();"); + + codeWriter.WriteLine("var jsonBodyOrServiceTypeTuples = new (bool, Type)[] {"); + codeWriter.Indent++; + foreach (var parameter in potentialImplicitBodyParameters) + { + codeWriter.WriteLine($$"""({{(parameter.IsOptional ? "true" : "false")}}, typeof({{parameter.Type.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability)}})),"""); + } + codeWriter.Indent--; + codeWriter.WriteLine("};"); + codeWriter.WriteLine("foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples)"); + codeWriter.StartBlock(); + codeWriter.WriteLine("if (!serviceProviderIsService.IsService(type))"); + codeWriter.StartBlock(); + codeWriter.WriteLine("options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType));"); + codeWriter.WriteLine("break;"); + codeWriter.EndBlock(); + codeWriter.EndBlock(); + } + else + { + codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.JsonContentType));"); + } + } + + public static void EmitAcceptsMetadata(this Endpoint endpoint, CodeWriter codeWriter) + { + var hasJsonBody = endpoint.EmitterContext.HasJsonBody || endpoint.EmitterContext.HasJsonBodyOrService; + + if (endpoint.EmitterContext.HasFormBody) + { + endpoint.EmitFormAcceptsMetadata(codeWriter); + } + else if (hasJsonBody) + { + endpoint.EmitJsonAcceptsMetadata(codeWriter); + } + } + + /* + * Helpers that are used for parameter preparation code. + */ private static string EmitParameterDiagnosticComment(this EndpointParameter endpointParameter) => $"// Endpoint Parameter: {endpointParameter.SymbolName} (Type = {endpointParameter.Type}, IsOptional = {endpointParameter.IsOptional}, IsParsable = {endpointParameter.IsParsable}, IsArray = {endpointParameter.IsArray}, Source = {endpointParameter.Source})"; private static string EmitTempArgument(this EndpointParameter endpointParameter) => $"{endpointParameter.SymbolName}_temp"; private static string EmitParsedTempArgument(this EndpointParameter endpointParameter) => $"{endpointParameter.SymbolName}_parsed_temp"; private static string EmitAssigningCodeResult(this EndpointParameter endpointParameter) => $"{endpointParameter.SymbolName}_raw"; + public static void EmitLoggingPreamble(this Endpoint endpoint, CodeWriter codeWriter) + { + if (endpoint.EmitterContext.RequiresLoggingHelper) + { + codeWriter.WriteLine("var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options);"); + } + } } diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs new file mode 100644 index 000000000000..433c1fddb377 --- /dev/null +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs @@ -0,0 +1,92 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; +using Microsoft.CodeAnalysis; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; + +internal static class EndpointResponseEmitter +{ + internal static void EmitJsonPreparation(this EndpointResponse endpointResponse, CodeWriter codeWriter) + { + if (endpointResponse.IsSerializableJsonResponse(out var responseType)) + { + var typeName = responseType.ToDisplayString(EmitterConstants.DisplayFormat); + + codeWriter.WriteLine("var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions;"); + codeWriter.WriteLine($"var jsonTypeInfo = (JsonTypeInfo<{typeName}>)serializerOptions.GetTypeInfo(typeof({typeName}));"); + } + } + + private static string EmitJsonResponse(this EndpointResponse endpointResponse) + { + if (endpointResponse.ResponseType != null && + (endpointResponse.ResponseType.IsSealed || endpointResponse.ResponseType.IsValueType)) + { + return $"httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo);"; + } + return $"GeneratedRouteBuilderExtensionsCore.WriteToResponseAsync(result, httpContext, jsonTypeInfo);"; + } + + internal static string EmitResponseWritingCall(this EndpointResponse endpointResponse, bool isAwaitable) + { + var returnOrAwait = isAwaitable ? "await" : "return"; + + if (endpointResponse.IsIResult) + { + return $"{returnOrAwait} GeneratedRouteBuilderExtensionsCore.ExecuteAsyncExplicit(result, httpContext);"; + } + if (endpointResponse.ResponseType?.SpecialType == SpecialType.System_String) + { + return $"{returnOrAwait} httpContext.Response.WriteAsync(result);"; + } + if (endpointResponse.ResponseType?.SpecialType == SpecialType.System_Object) + { + return $"{returnOrAwait} GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext);"; + } + if (!endpointResponse.HasNoResponse) + { + return $"{returnOrAwait} {endpointResponse.EmitJsonResponse()}"; + } + if (!endpointResponse.IsAwaitable && endpointResponse.HasNoResponse) + { + return $"{returnOrAwait} Task.CompletedTask;"; + } + return $"{returnOrAwait} httpContext.Response.WriteAsync(result);"; + } + + internal static void EmitBuiltinResponseTypeMetadata(this Endpoint endpoint, CodeWriter codeWriter) + { + if (endpoint.Response is not { } response || response.ResponseType is not { } responseType) + { + return; + } + + if (response.HasNoResponse || response.IsIResult) + { + return; + } + + if (responseType.SpecialType == SpecialType.System_String) + { + codeWriter.WriteLine("options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType));"); + } + else + { + codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof({responseType.ToDisplayString(EmitterConstants.DisplayFormat)}), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType));"); + } + } + + internal static void EmitCallToMetadataProviderForResponse(this Endpoint endpoint, CodeWriter codeWriter) + { + if (endpoint.Response is not { } response || response.ResponseType is not { } responseType) + { + return; + } + + if (response.IsEndpointMetadataProvider) + { + codeWriter.WriteLine($"PopulateMetadataForEndpoint<{responseType.ToDisplayString(EmitterConstants.DisplayFormat)}>(methodInfo, options.EndpointBuilder);"); + } + } +} diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Model/ConstructorParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/ConstructorParameter.cs similarity index 93% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Model/ConstructorParameter.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Model/ConstructorParameter.cs index 82fee4e2020f..6c1ec5b48b08 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Model/ConstructorParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/ConstructorParameter.cs @@ -2,6 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.CodeAnalysis; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; internal record ConstructorParameter(IPropertySymbol Property, IParameterSymbol? Parameter); diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs similarity index 91% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs index b9e2890ecd3a..7d8ead63e021 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs @@ -6,12 +6,12 @@ using System.Linq; using Microsoft.AspNetCore.Analyzers.Infrastructure; using Microsoft.AspNetCore.App.Analyzers.Infrastructure; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Operations; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; internal class Endpoint { @@ -96,7 +96,7 @@ public Endpoint(IInvocationOperation operation, WellKnownTypes wellKnownTypes, S public EndpointParameter[] Parameters { get; } = Array.Empty(); public List Diagnostics { get; } = new List(); - public (string File, int LineNumber) Location { get; } + public (string File, int LineNumber, int CharaceterNumber) Location { get; } public IInvocationOperation Operation { get; } public override bool Equals(object o) => @@ -139,13 +139,16 @@ public static int GetSignatureHashCode(Endpoint endpoint) return hashCode.ToHashCode(); } - private static (string, int) GetLocation(IInvocationOperation operation) + private static (string, int, int) GetLocation(IInvocationOperation operation) { var operationSpan = operation.Syntax.Span; var filePath = operation.Syntax.SyntaxTree.GetDisplayPath(operationSpan, operation.SemanticModel?.Compilation.Options.SourceReferenceResolver); var span = operation.Syntax.SyntaxTree.GetLineSpan(operationSpan); var lineNumber = span.StartLinePosition.Line + 1; - return (filePath, lineNumber); + // Calculate the character offset to the end of the Map invocation detected + var invocationLength = ((MemberAccessExpressionSyntax)((InvocationExpressionSyntax)operation.Syntax).Expression).Expression.Span.Length; + var characterNumber = span.StartLinePosition.Character + invocationLength + 1; + return (filePath, lineNumber, characterNumber); } private static string GetHttpMethod(IInvocationOperation operation) diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointDelegateComparer.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointDelegateComparer.cs similarity index 96% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointDelegateComparer.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointDelegateComparer.cs index c960a870613f..5cbdf81d326c 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointDelegateComparer.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointDelegateComparer.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; internal sealed class EndpointDelegateComparer : IEqualityComparer { diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointParameter.cs similarity index 99% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointParameter.cs index bd2aee82f3b1..2bf24982502e 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointParameter.cs @@ -10,12 +10,12 @@ using Microsoft.AspNetCore.Analyzers.Infrastructure; using Microsoft.AspNetCore.Analyzers.RouteEmbeddedLanguage.Infrastructure; using Microsoft.AspNetCore.App.Analyzers.Infrastructure; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using WellKnownType = Microsoft.AspNetCore.App.Analyzers.Infrastructure.WellKnownTypeData.WellKnownType; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; internal class EndpointParameter { @@ -23,6 +23,7 @@ public EndpointParameter(Endpoint endpoint, IParameterSymbol parameter, WellKnow { Ordinal = parameter.Ordinal; IsOptional = parameter.IsOptional(); + HasDefaultValue = parameter.HasExplicitDefaultValue; DefaultValue = parameter.GetDefaultValueString(); ProcessEndpointParameterSource(endpoint, parameter, parameter.GetAttributes(), wellKnownTypes); } @@ -32,6 +33,7 @@ private EndpointParameter(Endpoint endpoint, IPropertySymbol property, IParamete Ordinal = parameter?.Ordinal ?? 0; IsProperty = true; IsOptional = property.IsOptional() || parameter?.IsOptional() == true; + HasDefaultValue = parameter?.HasExplicitDefaultValue ?? false; DefaultValue = parameter?.GetDefaultValueString() ?? "null"; // Coalesce attributes on the property and attributes on the matching parameter var attributeBuilder = ImmutableArray.CreateBuilder(); @@ -251,6 +253,7 @@ private static bool ImplementsIEndpointParameterMetadataProvider(ITypeSymbol typ public bool IsOptional { get; set; } public bool IsArray { get; set; } public string DefaultValue { get; set; } = "null"; + public bool HasDefaultValue { get; set; } [MemberNotNullWhen(true, nameof(PropertyAsParameterInfoConstruction))] public bool IsProperty { get; set; } public EndpointParameterSource Source { get; set; } diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameterSource.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointParameterSource.cs similarity index 97% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameterSource.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointParameterSource.cs index d8410775a278..18593f75e67e 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameterSource.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointParameterSource.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; internal enum EndpointParameterSource { diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointResponse.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointResponse.cs similarity index 99% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointResponse.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointResponse.cs index ec99758412a6..eb489c68e149 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointResponse.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/EndpointResponse.cs @@ -4,10 +4,10 @@ using System; using Microsoft.AspNetCore.Analyzers.RouteEmbeddedLanguage.Infrastructure; using Microsoft.AspNetCore.App.Analyzers.Infrastructure; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters; using Microsoft.CodeAnalysis; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using WellKnownType = WellKnownTypeData.WellKnownType; diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/InvocationOperationExtensions.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/InvocationOperationExtensions.cs similarity index 99% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/InvocationOperationExtensions.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Model/InvocationOperationExtensions.cs index 8907d10c778d..b5b9af44b6b9 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/InvocationOperationExtensions.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/InvocationOperationExtensions.cs @@ -6,7 +6,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Operations; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; internal static class InvocationOperationExtensions { diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Model/ParameterLookupKey.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/ParameterLookupKey.cs similarity index 97% rename from src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Model/ParameterLookupKey.cs rename to src/Http/Http.Extensions/gen/StaticRouteHandler/Model/ParameterLookupKey.cs index 55da4a664165..7615bc0863a4 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Model/ParameterLookupKey.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/ParameterLookupKey.cs @@ -5,7 +5,7 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; internal sealed class ParameterLookupKey { diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointEmitter.cs deleted file mode 100644 index b4e311b86ee4..000000000000 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointEmitter.cs +++ /dev/null @@ -1,132 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using System.Globalization; -using System.IO; -using System.Linq; - -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; -internal static class EndpointEmitter -{ - internal static string EmitParameterPreparation(this IEnumerable endpointParameters, EmitterContext emitterContext, int baseIndent = 0) - { - using var stringWriter = new StringWriter(CultureInfo.InvariantCulture); - using var parameterPreparationBuilder = new CodeWriter(stringWriter, baseIndent); - var readFormEmitted = false; - - foreach (var parameter in endpointParameters) - { - switch (parameter.Source) - { - case EndpointParameterSource.SpecialType: - parameter.EmitSpecialParameterPreparation(parameterPreparationBuilder); - break; - case EndpointParameterSource.Query: - case EndpointParameterSource.Header: - parameter.EmitQueryOrHeaderParameterPreparation(parameterPreparationBuilder); - break; - case EndpointParameterSource.Route: - parameter.EmitRouteParameterPreparation(parameterPreparationBuilder); - break; - case EndpointParameterSource.RouteOrQuery: - emitterContext.HasRouteOrQuery = true; - parameter.EmitRouteOrQueryParameterPreparation(parameterPreparationBuilder); - break; - case EndpointParameterSource.BindAsync: - emitterContext.HasBindAsync = true; - parameter.EmitBindAsyncPreparation(parameterPreparationBuilder); - break; - case EndpointParameterSource.JsonBody: - parameter.EmitJsonBodyParameterPreparationString(parameterPreparationBuilder); - break; - case EndpointParameterSource.FormBody: - parameter.EmitFormParameterPreparation(parameterPreparationBuilder, ref readFormEmitted); - break; - case EndpointParameterSource.JsonBodyOrService: - parameter.EmitJsonBodyOrServiceParameterPreparationString(parameterPreparationBuilder); - break; - case EndpointParameterSource.JsonBodyOrQuery: - parameter.EmitJsonBodyOrQueryParameterPreparationString(parameterPreparationBuilder); - break; - case EndpointParameterSource.Service: - parameter.EmitServiceParameterPreparation(parameterPreparationBuilder); - break; - case EndpointParameterSource.AsParameters: - parameter.EmitAsParametersParameterPreparation(parameterPreparationBuilder, emitterContext); - break; - } - } - - return stringWriter.ToString(); - } - - public static void EmitRouteOrQueryResolver(this Endpoint endpoint, CodeWriter codeWriter) - { - foreach (var parameter in endpoint.Parameters) - { - ProcessParameter(parameter, codeWriter, endpoint); - if (parameter is { Source: EndpointParameterSource.AsParameters, EndpointParameters: {} innerParameters }) - { - foreach (var innerParameter in innerParameters) - { - ProcessParameter(innerParameter, codeWriter, endpoint); - } - } - } - - static void ProcessParameter(EndpointParameter parameter, CodeWriter codeWriter, Endpoint endpoint) - { - if (parameter.Source == EndpointParameterSource.RouteOrQuery) - { - var parameterName = parameter.SymbolName; - codeWriter.Write($@"var {parameterName}_RouteOrQueryResolver = "); - codeWriter.WriteLine($@"GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery(""{parameterName}"", options.RouteParameterNames);"); - endpoint.EmitterContext.HasRouteOrQuery = true; - } - } - } - - public static void EmitJsonBodyOrServiceResolver(this Endpoint endpoint, CodeWriter codeWriter) - { - var serviceProviderEmitted = false; - foreach (var parameter in endpoint.Parameters) - { - ProcessParameter(parameter, codeWriter, ref serviceProviderEmitted); - if (parameter is { Source: EndpointParameterSource.AsParameters, EndpointParameters: {} innerParameters }) - { - foreach (var innerParameter in innerParameters) - { - ProcessParameter(innerParameter, codeWriter, ref serviceProviderEmitted); - } - } - } - - static void ProcessParameter(EndpointParameter parameter, CodeWriter codeWriter, ref bool serviceProviderEmitted) - { - if (parameter.Source == EndpointParameterSource.JsonBodyOrService) - { - if (!serviceProviderEmitted) - { - codeWriter.WriteLine("var serviceProviderIsService = serviceProvider?.GetService();"); - serviceProviderEmitted = true; - } - codeWriter.Write($@"var {parameter.SymbolName}_JsonBodyOrServiceResolver = "); - var shortParameterTypeName = parameter.Type.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat); - codeWriter.WriteLine($"ResolveJsonBodyOrService<{parameter.Type.ToDisplayString(EmitterConstants.DisplayFormat)}>(logOrThrowExceptionHelper, {SymbolDisplay.FormatLiteral(shortParameterTypeName, true)}, {SymbolDisplay.FormatLiteral(parameter.SymbolName, true)}, serviceProviderIsService);"); - } - } - } - - public static void EmitLoggingPreamble(this Endpoint endpoint, CodeWriter codeWriter) - { - if (endpoint.EmitterContext.RequiresLoggingHelper) - { - codeWriter.WriteLine("var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options);"); - } - } - - public static string EmitArgumentList(this Endpoint endpoint) => string.Join(", ", endpoint.Parameters.Select(p => p.EmitArgument())); -} diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointJsonResponseEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointJsonResponseEmitter.cs deleted file mode 100644 index 0f542bc3cf5f..000000000000 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointJsonResponseEmitter.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; - -internal static class EndpointJsonResponseEmitter -{ - internal static void EmitJsonPreparation(this EndpointResponse endpointResponse, CodeWriter codeWriter) - { - if (endpointResponse.IsSerializableJsonResponse(out var responseType)) - { - var typeName = responseType.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability); - - codeWriter.WriteLine("var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions;"); - codeWriter.WriteLine($"var jsonTypeInfo = (JsonTypeInfo<{typeName}>)serializerOptions.GetTypeInfo(typeof({typeName}));"); - } - } - - internal static string EmitJsonResponse(this EndpointResponse endpointResponse) - { - if (endpointResponse.ResponseType != null && - (endpointResponse.ResponseType.IsSealed || endpointResponse.ResponseType.IsValueType)) - { - return $"httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo);"; - } - return $"GeneratedRouteBuilderExtensionsCore.WriteToResponseAsync(result, httpContext, jsonTypeInfo);"; - } -} diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Emitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Emitter.cs deleted file mode 100644 index df0688d687be..000000000000 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Emitter.cs +++ /dev/null @@ -1,420 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters; -using Microsoft.CodeAnalysis; - -namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; - -internal static class StaticRouteHandlerModelEmitter -{ - public static string EmitHandlerDelegateType(this Endpoint endpoint, bool considerOptionality = false) - { - if (endpoint.Parameters.Length == 0) - { - return endpoint.Response == null || (endpoint.Response.HasNoResponse && !endpoint.Response.IsAwaitable) ? "System.Action" : $"System.Func<{endpoint.Response.WrappedResponseType}>"; - } - var parameterTypeList = string.Join(", ", endpoint.Parameters.Select(p => considerOptionality - ? p.Type.ToDisplayString(p.IsOptional ? NullableFlowState.MaybeNull : NullableFlowState.NotNull, EmitterConstants.DisplayFormat) - : p.Type.ToDisplayString(EmitterConstants.DisplayFormat))); - - if (endpoint.Response == null || (endpoint.Response.HasNoResponse && !endpoint.Response.IsAwaitable)) - { - return $"System.Action<{parameterTypeList}>"; - } - return $"System.Func<{parameterTypeList}, {endpoint.Response.WrappedResponseType}>"; - } - - public static string EmitSourceKey(this Endpoint endpoint) - { - return $@"(@""{endpoint.Location.File}"", {endpoint.Location.LineNumber})"; - } - - public static string EmitVerb(this Endpoint endpoint) - { - return endpoint.HttpMethod switch - { - "MapGet" => "GetVerb", - "MapPut" => "PutVerb", - "MapPost" => "PostVerb", - "MapDelete" => "DeleteVerb", - "MapPatch" => "PatchVerb", - "MapMethods" => "httpMethods", - "Map" => "null", - "MapFallback" => "null", - _ => throw new ArgumentException($"Received unexpected HTTP method: {endpoint.HttpMethod}") - }; - } - - /* - * Emit invocation to the request handler. The structure - * involved here consists of a call to bind parameters, check - * their validity (optionality), invoke the underlying handler with - * the arguments bound from HTTP context, and write out the response. - */ - public static void EmitRequestHandler(this Endpoint endpoint, CodeWriter codeWriter) - { - codeWriter.WriteLine(endpoint.IsAwaitable ? "async Task RequestHandler(HttpContext httpContext)" : "Task RequestHandler(HttpContext httpContext)"); - codeWriter.StartBlock(); // Start handler method block - codeWriter.WriteLine("var wasParamCheckFailure = false;"); - - if (endpoint.Parameters.Length > 0) - { - codeWriter.WriteLine(endpoint.Parameters.EmitParameterPreparation(endpoint.EmitterContext, codeWriter.Indent)); - } - - codeWriter.WriteLine("if (wasParamCheckFailure)"); - codeWriter.StartBlock(); // Start if-statement block - codeWriter.WriteLine("httpContext.Response.StatusCode = 400;"); - codeWriter.WriteLine(endpoint.IsAwaitable ? "return;" : "return Task.CompletedTask;"); - codeWriter.EndBlock(); // End if-statement block - if (endpoint.Response == null) - { - return; - } - if (!endpoint.Response.HasNoResponse) - { - codeWriter.Write("var result = "); - } - if (endpoint.Response.IsAwaitable) - { - codeWriter.Write("await "); - } - codeWriter.WriteLine($"handler({endpoint.EmitArgumentList()});"); - - endpoint.Response.EmitHttpResponseContentType(codeWriter); - - if (!endpoint.Response.HasNoResponse) - { - codeWriter.WriteLine(endpoint.Response.EmitResponseWritingCall(endpoint.IsAwaitable)); - } - else if (!endpoint.IsAwaitable) - { - codeWriter.WriteLine("return Task.CompletedTask;"); - } - - codeWriter.EndBlock(); // End handler method block - } - - private static void EmitHttpResponseContentType(this EndpointResponse endpointResponse, CodeWriter codeWriter) - { - if (!endpointResponse.HasNoResponse - && endpointResponse.ResponseType is { } responseType - && (responseType.SpecialType == SpecialType.System_Object || responseType.SpecialType == SpecialType.System_String)) - { - codeWriter.WriteLine("if (result is string)"); - codeWriter.StartBlock(); - codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""text/plain; charset=utf-8"";"); - codeWriter.EndBlock(); - codeWriter.WriteLine("else"); - codeWriter.StartBlock(); - codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""application/json; charset=utf-8"";"); - codeWriter.EndBlock(); - } - } - - private static string EmitResponseWritingCall(this EndpointResponse endpointResponse, bool isAwaitable) - { - var returnOrAwait = isAwaitable ? "await" : "return"; - - if (endpointResponse.IsIResult) - { - return $"{returnOrAwait} GeneratedRouteBuilderExtensionsCore.ExecuteAsyncExplicit(result, httpContext);"; - } - else if (endpointResponse.ResponseType?.SpecialType == SpecialType.System_String) - { - return $"{returnOrAwait} httpContext.Response.WriteAsync(result);"; - } - else if (endpointResponse.ResponseType?.SpecialType == SpecialType.System_Object) - { - return $"{returnOrAwait} GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext);"; - } - else if (!endpointResponse.HasNoResponse) - { - return $"{returnOrAwait} {endpointResponse.EmitJsonResponse()}"; - } - else if (!endpointResponse.IsAwaitable && endpointResponse.HasNoResponse) - { - return $"{returnOrAwait} Task.CompletedTask;"; - } - else - { - return $"{returnOrAwait} httpContext.Response.WriteAsync(result);"; - } - } - - /* - * TODO: Emit invocation to the `filteredInvocation` pipeline by constructing - * the `EndpointFilterInvocationContext` using the bound arguments for the handler. - * In the source generator context, the generic overloads for `EndpointFilterInvocationContext` - * can be used to reduce the boxing that happens at runtime when constructing - * the context object. - */ - public static void EmitFilteredRequestHandler(this Endpoint endpoint, CodeWriter codeWriter) - { - var argumentList = endpoint.Parameters.Length == 0 ? string.Empty : $", {endpoint.EmitArgumentList()}"; - var invocationCreator = endpoint.Parameters.Length > 8 - ? "new DefaultEndpointFilterInvocationContext" - : "EndpointFilterInvocationContext.Create"; - var invocationGenericArgs = endpoint.Parameters.Length is > 0 and < 8 - ? $"<{endpoint.EmitFilterInvocationContextTypeArgs()}>" - : string.Empty; - - codeWriter.WriteLine("async Task RequestHandlerFiltered(HttpContext httpContext)"); - codeWriter.StartBlock(); // Start handler method block - codeWriter.WriteLine("var wasParamCheckFailure = false;"); - - if (endpoint.Parameters.Length > 0) - { - codeWriter.WriteLine(endpoint.Parameters.EmitParameterPreparation(endpoint.EmitterContext, codeWriter.Indent)); - } - - codeWriter.WriteLine("if (wasParamCheckFailure)"); - codeWriter.StartBlock(); // Start if-statement block - codeWriter.WriteLine("httpContext.Response.StatusCode = 400;"); - codeWriter.EndBlock(); // End if-statement block - codeWriter.WriteLine($"var result = await filteredInvocation({invocationCreator}{invocationGenericArgs}(httpContext{argumentList}));"); - codeWriter.WriteLine("await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext);"); - codeWriter.EndBlock(); // End handler method block - } - - private static void EmitBuiltinResponseTypeMetadata(this Endpoint endpoint, CodeWriter codeWriter) - { - if (endpoint.Response is not { } response || response.ResponseType is not { } responseType) - { - return; - } - - if (response.HasNoResponse || response.IsIResult) - { - return; - } - - if (responseType.SpecialType == SpecialType.System_String) - { - codeWriter.WriteLine("options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType));"); - } - else - { - codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof({responseType.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability)}), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType));"); - } - } - - private static void EmitCallToMetadataProviderForResponse(this Endpoint endpoint, CodeWriter codeWriter) - { - if (endpoint.Response is not { } response || response.ResponseType is not { } responseType) - { - return; - } - - if (response.IsEndpointMetadataProvider) - { - codeWriter.WriteLine($"PopulateMetadataForEndpoint<{responseType.ToDisplayString(EmitterConstants.DisplayFormat)}>(methodInfo, options.EndpointBuilder);"); - } - } - private static void EmitCallsToMetadataProvidersForParameters(this Endpoint endpoint, CodeWriter codeWriter) - { - if (endpoint.EmitterContext.HasEndpointParameterMetadataProvider) - { - codeWriter.WriteLine("var parameterInfos = methodInfo.GetParameters();"); - } - - foreach (var parameter in endpoint.Parameters) - { - if (parameter is { Source: EndpointParameterSource.AsParameters, EndpointParameters: { } innerParameters }) - { - foreach (var innerParameter in innerParameters) - { - ProcessParameter(innerParameter, codeWriter); - } - } - else - { - ProcessParameter(parameter, codeWriter); - } - } - - static void ProcessParameter(EndpointParameter parameter, CodeWriter codeWriter) - { - if (parameter.Type is not { } parameterType) - { - return; - } - - if (parameter.IsEndpointParameterMetadataProvider) - { - var resolveParameterInfo = parameter.IsProperty - ? parameter.PropertyAsParameterInfoConstruction - : $"parameterInfos[{parameter.Ordinal}]"; - codeWriter.WriteLine($"var {parameter.SymbolName}_ParameterInfo = {resolveParameterInfo};"); - codeWriter.WriteLine($"PopulateMetadataForParameter<{parameterType.ToDisplayString(EmitterConstants.DisplayFormat)}>({parameter.SymbolName}_ParameterInfo, options.EndpointBuilder);"); - } - - if (parameter.IsEndpointMetadataProvider) - { - codeWriter.WriteLine($"PopulateMetadataForEndpoint<{parameterType.ToDisplayString(EmitterConstants.DisplayFormat)}>(methodInfo, options.EndpointBuilder);"); - } - - } - } - - public static void EmitFormAcceptsMetadata(this Endpoint endpoint, CodeWriter codeWriter) - { - var hasFormFiles = endpoint.Parameters.Any(p => p.IsFormFile); - - if (hasFormFiles) - { - codeWriter.WriteLine("options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.FormFileContentType));"); - } - else - { - codeWriter.WriteLine("options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.FormContentType));"); - } - } - - public static void EmitJsonAcceptsMetadata(this Endpoint endpoint, CodeWriter codeWriter) - { - EndpointParameter? explicitBodyParameter = null; - var potentialImplicitBodyParameters = new List(); - - foreach (var parameter in endpoint.Parameters) - { - if (explicitBodyParameter == null && parameter.Source == EndpointParameterSource.JsonBody) - { - explicitBodyParameter = parameter; - break; - } - else if (parameter.Source == EndpointParameterSource.JsonBodyOrService || parameter.Source == EndpointParameterSource.JsonBodyOrQuery) - { - potentialImplicitBodyParameters.Add(parameter); - } - } - - if (explicitBodyParameter != null) - { - codeWriter.WriteLine($$"""options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof({{explicitBodyParameter.Type.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability)}}), isOptional: {{(explicitBodyParameter.IsOptional ? "true" : "false")}}, contentTypes: GeneratedMetadataConstants.JsonContentType));"""); - } - else if (potentialImplicitBodyParameters.Count > 0) - { - codeWriter.WriteLine("var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices;"); - codeWriter.WriteLine($"var serviceProviderIsService = serviceProvider.GetRequiredService();"); - - codeWriter.WriteLine("var jsonBodyOrServiceTypeTuples = new (bool, Type)[] {"); - codeWriter.Indent++; - foreach (var parameter in potentialImplicitBodyParameters) - { - codeWriter.WriteLine($$"""({{(parameter.IsOptional ? "true" : "false")}}, typeof({{parameter.Type.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability)}})),"""); - } - codeWriter.Indent--; - codeWriter.WriteLine("};"); - codeWriter.WriteLine("foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples)"); - codeWriter.StartBlock(); - codeWriter.WriteLine("if (!serviceProviderIsService.IsService(type))"); - codeWriter.StartBlock(); - codeWriter.WriteLine("options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType));"); - codeWriter.WriteLine("break;"); - codeWriter.EndBlock(); - codeWriter.EndBlock(); - } - else - { - codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.JsonContentType));"); - } - } - - public static void EmitAcceptsMetadata(this Endpoint endpoint, CodeWriter codeWriter) - { - var hasJsonBody = endpoint.EmitterContext.HasJsonBody || endpoint.EmitterContext.HasJsonBodyOrService || endpoint.EmitterContext.HasJsonBodyOrQuery; - - if (endpoint.EmitterContext.HasFormBody) - { - endpoint.EmitFormAcceptsMetadata(codeWriter); - } - else if (hasJsonBody) - { - endpoint.EmitJsonAcceptsMetadata(codeWriter); - } - } - - public static void EmitEndpointMetadataPopulation(this Endpoint endpoint, CodeWriter codeWriter) - { - endpoint.EmitAcceptsMetadata(codeWriter); - endpoint.EmitBuiltinResponseTypeMetadata(codeWriter); - endpoint.EmitCallsToMetadataProvidersForParameters(codeWriter); - endpoint.EmitCallToMetadataProviderForResponse(codeWriter); - } - - public static void EmitFilteredInvocation(this Endpoint endpoint, CodeWriter codeWriter) - { - if (endpoint.Response?.HasNoResponse == true) - { - codeWriter.WriteLine(endpoint.Response?.IsAwaitable == true - ? $"await handler({endpoint.EmitFilteredArgumentList()});" - : $"handler({endpoint.EmitFilteredArgumentList()});"); - codeWriter.WriteLine(endpoint.Response?.IsAwaitable == true - ? "return (object?)Results.Empty;" - : "return ValueTask.FromResult(Results.Empty);"); - } - else if (endpoint.Response?.IsAwaitable == true) - { - codeWriter.WriteLine($"var result = await handler({endpoint.EmitFilteredArgumentList()});"); - codeWriter.WriteLine("return (object?)result;"); - } - else - { - codeWriter.WriteLine($"return ValueTask.FromResult(handler({endpoint.EmitFilteredArgumentList()}));"); - } - } - - public static string EmitFilteredArgumentList(this Endpoint endpoint) - { - if (endpoint.Parameters.Length == 0) - { - return string.Empty; - } - - var sb = new StringBuilder(); - - for (var i = 0; i < endpoint.Parameters.Length; i++) - { - // The null suppression operator on the GetArgument(...) call here is required because we'll occassionally be - // dealing with nullable types here. We could try to do fancy things to branch the logic here depending on - // the nullability, but at the end of the day we are going to call GetArguments(...) - at runtime the nullability - // suppression operator doesn't come into play - so its not worth worrying about. - sb.Append($"ic.GetArgument<{endpoint.Parameters[i].Type.ToDisplayString(EmitterConstants.DisplayFormat)}>({i})!"); - - if (i < endpoint.Parameters.Length - 1) - { - sb.Append(", "); - } - } - - return sb.ToString(); - } - - public static string EmitFilterInvocationContextTypeArgs(this Endpoint endpoint) - { - if (endpoint.Parameters.Length == 0) - { - return string.Empty; - } - - var sb = new StringBuilder(); - - for (var i = 0; i < endpoint.Parameters.Length; i++) - { - sb.Append(endpoint.Parameters[i].Type.ToDisplayString(endpoint.Parameters[i].IsOptional ? NullableFlowState.MaybeNull : NullableFlowState.NotNull, EmitterConstants.DisplayFormat)); - - if (i < endpoint.Parameters.Length - 1) - { - sb.Append(", "); - } - } - - return sb.ToString(); - } -} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt index 934f3010e7fe..f9dec7d0b84d 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt @@ -22,14 +22,52 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} + +namespace System.Runtime.CompilerServices +{ + %GENERATEDCODEATTRIBUTE% + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + } + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; + using System.Globalization; + using System.Linq; + using System.Reflection; + using System.Text.Json; + using System.Text.Json.Serialization.Metadata; + using System.Threading.Tasks; + using System.IO; + using Microsoft.AspNetCore.Routing; + using Microsoft.AspNetCore.Routing.Patterns; + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Http.Json; + using Microsoft.AspNetCore.Http.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Primitives; + using Microsoft.Extensions.Options; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + file static class GeneratedRouteBuilderExtensionsCore { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; @@ -37,2093 +75,1896 @@ namespace Microsoft.AspNetCore.Builder private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord.BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncRecord", "myBindAsyncParam", "MyBindAsyncRecord.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord.BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncRecord", "myBindAsyncParam", "MyBindAsyncRecord.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord.BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord.BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct.BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncStruct", "myBindAsyncParam", "MyBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct.BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncStruct", "myBindAsyncParam", "MyBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 28, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_28( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 28)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct.BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct.BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 29, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_29( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 29)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyNullableBindAsyncStruct", "myBindAsyncParam", "MyNullableBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyNullableBindAsyncStruct", "myBindAsyncParam", "MyNullableBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 30, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_30( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 30)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 31, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_31( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 31)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct.BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBothBindAsyncStruct", "myBindAsyncParam", "MyBothBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct.BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBothBindAsyncStruct", "myBindAsyncParam", "MyBothBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 32, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_32( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 32)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct.BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct.BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 33, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_33( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 33)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord.BindAsync(httpContext); + global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MySimpleBindAsyncRecord", "myBindAsyncParam", "MySimpleBindAsyncRecord.BindAsync(HttpContext)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord.BindAsync(httpContext); + global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MySimpleBindAsyncRecord", "myBindAsyncParam", "MySimpleBindAsyncRecord.BindAsync(HttpContext)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord)myBindAsyncParam_temp; + } + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 34, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_34( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + global::System.Delegate handler) { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 34)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) + { + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord.BindAsync(httpContext); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord.BindAsync(httpContext); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, GetVerb, - filePath, - lineNumber); + populateMetadata, + createRequestDelegate); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 35, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_35( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - - } -} - -namespace Microsoft.AspNetCore.Http.Generated -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Diagnostics.CodeAnalysis; - using System.Globalization; - using System.Linq; - using System.Reflection; - using System.Text.Json; - using System.Text.Json.Serialization.Metadata; - using System.Threading.Tasks; - using System.IO; - using Microsoft.AspNetCore.Routing; - using Microsoft.AspNetCore.Routing.Patterns; - using Microsoft.AspNetCore.Builder; - using Microsoft.AspNetCore.Http; - using Microsoft.AspNetCore.Http.Json; - using Microsoft.AspNetCore.Http.Metadata; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.FileProviders; - using Microsoft.Extensions.Logging; - using Microsoft.Extensions.Primitives; - using Microsoft.Extensions.Options; - - using MetadataPopulator = System.Func; - using RequestDelegateFactoryFunc = System.Func; - - %GENERATEDCODEATTRIBUTE% - file static class GeneratedRouteBuilderExtensionsCore - { - - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 35)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord.BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncRecord", "myBindAsyncParam", "MyBindAsyncRecord.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord)myBindAsyncParam_temp; - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); - } - - async Task RequestHandlerFiltered(HttpContext httpContext) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord.BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) + if (ic.HttpContext.Response.StatusCode == 400) { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncRecord", "myBindAsyncParam", "MyBindAsyncRecord.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord)myBindAsyncParam_temp; + return ValueTask.FromResult(Results.Empty); } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 26)] = ( - (methodInfo, options) => + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct.BindAsync(httpContext); + global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord.BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + logOrThrowExceptionHelper.RequiredParameterNotProvided("MySimpleBindAsyncStruct", "myBindAsyncParam", "MySimpleBindAsyncStruct.BindAsync(HttpContext)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; } - - async Task RequestHandlerFiltered(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord.BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } - - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 27)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct.BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncStruct", "myBindAsyncParam", "MyBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct)myBindAsyncParam_temp; - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct)myBindAsyncParam_temp; } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct.BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncStruct", "myBindAsyncParam", "MyBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct)myBindAsyncParam_temp; - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 28)] = ( - (methodInfo, options) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 28)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct.BindAsync(httpContext); + global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MySimpleBindAsyncStruct", "myBindAsyncParam", "MySimpleBindAsyncStruct.BindAsync(HttpContext)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct.BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct)myBindAsyncParam_temp; } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct.BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 29)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 29)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyNullableBindAsyncStruct", "myBindAsyncParam", "MyNullableBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct)myBindAsyncParam_temp; - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); - } + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - async Task RequestHandlerFiltered(HttpContext httpContext) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 36, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_36( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 36)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyNullableBindAsyncStruct", "myBindAsyncParam", "MyNullableBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else + if (ic.HttpContext.Response.StatusCode == 400) { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct)myBindAsyncParam_temp; + return ValueTask.FromResult(Results.Empty); } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 30)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 30)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct.BindAsync(httpContext); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct?)myBindAsyncParam_temp; - async Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct.BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } - - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 31)] = ( - (methodInfo, options) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 31)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct.BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBothBindAsyncStruct", "myBindAsyncParam", "MyBothBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct)myBindAsyncParam_temp; - } + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct.BindAsync(httpContext); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct?)myBindAsyncParam_temp; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - async Task RequestHandlerFiltered(HttpContext httpContext) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 37, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_37( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 37)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct.BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) + if (ic.HttpContext.Response.StatusCode == 400) { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBothBindAsyncStruct", "myBindAsyncParam", "MyBothBindAsyncStruct.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct)myBindAsyncParam_temp; + return ValueTask.FromResult(Results.Empty); } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 32)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 32)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("BindAsyncFromImplicitStaticAbstractInterface", "myBindAsyncParam", "BindAsyncFromImplicitStaticAbstractInterface.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct.BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface)myBindAsyncParam_temp; } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct.BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 33)] = ( - (methodInfo, options) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 33)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord.BindAsync(httpContext); - global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MySimpleBindAsyncRecord", "myBindAsyncParam", "MySimpleBindAsyncRecord.BindAsync(HttpContext)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord)myBindAsyncParam_temp; - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("BindAsyncFromImplicitStaticAbstractInterface", "myBindAsyncParam", "BindAsyncFromImplicitStaticAbstractInterface.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; } - - async Task RequestHandlerFiltered(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord.BindAsync(httpContext); - global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MySimpleBindAsyncRecord", "myBindAsyncParam", "MySimpleBindAsyncRecord.BindAsync(HttpContext)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord)myBindAsyncParam_temp; - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface)myBindAsyncParam_temp; } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 34)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 34)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord.BindAsync(httpContext); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord?)myBindAsyncParam_temp; + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 38, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_38( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 38)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + return ValueTask.FromResult(Results.Empty); } - await httpContext.Response.WriteAsync(result); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord.BindAsync(httpContext); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord?)myBindAsyncParam_temp; + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 35)] = ( - (methodInfo, options) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 35)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct.BindAsync(httpContext); - global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MySimpleBindAsyncStruct", "myBindAsyncParam", "MySimpleBindAsyncStruct.BindAsync(HttpContext)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct)myBindAsyncParam_temp; - } + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface?)myBindAsyncParam_temp; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - async Task RequestHandlerFiltered(HttpContext httpContext) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 39, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_39( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 39)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct.BindAsync(httpContext); - global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MySimpleBindAsyncStruct", "myBindAsyncParam", "MySimpleBindAsyncStruct.BindAsync(HttpContext)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else + if (ic.HttpContext.Response.StatusCode == 400) { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct)myBindAsyncParam_temp; + return ValueTask.FromResult(Results.Empty); } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 36)] = ( - (methodInfo, options) => + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 36)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync.BindAsync(httpContext); + global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("InheritBindAsync", "myBindAsyncParam", "InheritBindAsync.BindAsync(HttpContext)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct.BindAsync(httpContext); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync)myBindAsyncParam_temp; } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct.BindAsync(httpContext); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 37)] = ( - (methodInfo, options) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 37)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("BindAsyncFromImplicitStaticAbstractInterface", "myBindAsyncParam", "BindAsyncFromImplicitStaticAbstractInterface.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface)myBindAsyncParam_temp; - } + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync.BindAsync(httpContext); + global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("InheritBindAsync", "myBindAsyncParam", "InheritBindAsync.BindAsync(HttpContext)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync)myBindAsyncParam_temp; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - async Task RequestHandlerFiltered(HttpContext httpContext) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 40, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_40( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 40)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) + if (ic.HttpContext.Response.StatusCode == 400) { - logOrThrowExceptionHelper.RequiredParameterNotProvided("BindAsyncFromImplicitStaticAbstractInterface", "myBindAsyncParam", "BindAsyncFromImplicitStaticAbstractInterface.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface)myBindAsyncParam_temp; + return ValueTask.FromResult(Results.Empty); } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 38)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 38)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync.BindAsync(httpContext); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync?)myBindAsyncParam_temp; - async Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface?)myBindAsyncParam_temp; + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync.BindAsync(httpContext); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync?)myBindAsyncParam_temp; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 39)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 39)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 41, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_41( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 41)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync.BindAsync(httpContext); - global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("InheritBindAsync", "myBindAsyncParam", "InheritBindAsync.BindAsync(HttpContext)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync)myBindAsyncParam_temp; + return ValueTask.FromResult(Results.Empty); } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); - } + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync.BindAsync(httpContext); - global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("InheritBindAsync", "myBindAsyncParam", "InheritBindAsync.BindAsync(HttpContext)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync)myBindAsyncParam_temp; - } + logOrThrowExceptionHelper.RequiredParameterNotProvided("BindAsyncFromExplicitStaticAbstractInterface", "myBindAsyncParam", "BindAsyncFromExplicitStaticAbstractInterface.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface)myBindAsyncParam_temp; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 40)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 40)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[1]); + global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("BindAsyncFromExplicitStaticAbstractInterface", "myBindAsyncParam", "BindAsyncFromExplicitStaticAbstractInterface.BindAsync(HttpContext, ParameterInfo)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync.BindAsync(httpContext); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface)myBindAsyncParam_temp; } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync.BindAsync(httpContext); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync?)myBindAsyncParam_temp; + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - if (wasParamCheckFailure) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 42, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_42( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 42)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; + return ValueTask.FromResult(Results.Empty); } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 41)] = ( - (methodInfo, options) => + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var parameters = del.Method.GetParameters(); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 41)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface?)myBindAsyncParam_temp; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } + + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("BindAsyncFromExplicitStaticAbstractInterface", "myBindAsyncParam", "BindAsyncFromExplicitStaticAbstractInterface.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface)myBindAsyncParam_temp; - } + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[0]); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface?)myBindAsyncParam_temp; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - async Task RequestHandlerFiltered(HttpContext httpContext) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 43, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_43( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 43)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[1]); - global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("BindAsyncFromExplicitStaticAbstractInterface", "myBindAsyncParam", "BindAsyncFromExplicitStaticAbstractInterface.BindAsync(HttpContext, ParameterInfo)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else + if (ic.HttpContext.Response.StatusCode == 400) { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface)myBindAsyncParam_temp; + return ValueTask.FromResult(Results.Empty); } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 42)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 42)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var parameters = del.Method.GetParameters(); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.IBindAsync.BindAsync(httpContext); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncFromInterfaceRecord", "myBindAsyncParam", "MyBindAsyncFromInterfaceRecord.BindAsync(HttpContext)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord)myBindAsyncParam_temp; } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await BindAsync(httpContext, parameters[0]); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(httpContext_local, myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 43)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 43)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - async Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.IBindAsync.BindAsync(httpContext); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncFromInterfaceRecord", "myBindAsyncParam", "MyBindAsyncFromInterfaceRecord.BindAsync(HttpContext)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else - { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord)myBindAsyncParam_temp; - } + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.IBindAsync.BindAsync(httpContext); + global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord myBindAsyncParam_local; + if ((object?)myBindAsyncParam_temp == null) + { + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncFromInterfaceRecord", "myBindAsyncParam", "MyBindAsyncFromInterfaceRecord.BindAsync(HttpContext)"); + wasParamCheckFailure = true; + myBindAsyncParam_local = default!; + } + else + { + myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord)myBindAsyncParam_temp; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(httpContext_local, myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - async Task RequestHandlerFiltered(HttpContext httpContext) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 44, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_44( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 44)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.IBindAsync.BindAsync(httpContext); - global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord myBindAsyncParam_local; - if ((object?)myBindAsyncParam_temp == null) - { - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyBindAsyncFromInterfaceRecord", "myBindAsyncParam", "MyBindAsyncFromInterfaceRecord.BindAsync(HttpContext)"); - wasParamCheckFailure = true; - myBindAsyncParam_local = default!; - } - else + if (ic.HttpContext.Response.StatusCode == 400) { - myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord)myBindAsyncParam_temp; + return ValueTask.FromResult(Results.Empty); } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 44)] = ( - (methodInfo, options) => + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 44)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) - { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.IBindAsync.BindAsync(httpContext); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord?)myBindAsyncParam_temp; - async Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.IBindAsync.BindAsync(httpContext); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord?)myBindAsyncParam_temp; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(myBindAsyncParam_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(myBindAsyncParam_local); + await httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.IBindAsync.BindAsync(httpContext); - var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord?)myBindAsyncParam_temp; + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var myBindAsyncParam_temp = await global::Microsoft.AspNetCore.Http.Generators.Tests.IBindAsync.BindAsync(httpContext); + var myBindAsyncParam_local = (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord?)myBindAsyncParam_temp; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt index 915af282c6dd..35713d096149 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func> handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - PostVerb, - filePath, - lineNumber); } - } } @@ -89,180 +69,214 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), isOptional: false, contentTypes: GeneratedMetadataConstants.JsonContentType)); - PopulateMetadataForEndpoint>(methodInfo, options.EndpointBuilder); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), isOptional: false, contentTypes: GeneratedMetadataConstants.JsonContentType)); + PopulateMetadataForEndpoint>(methodInfo, options.EndpointBuilder); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::Microsoft.AspNetCore.Http.HttpResults.Ok (global::Microsoft.AspNetCore.Http.Generators.Tests.Todo arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func>)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBody) + var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "Todo", "todo"); + var todo_local = todo_resolveBodyResult.Item2; + if (!todo_resolveBodyResult.Item1) + { + return; } - async Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBody) - var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "Todo", "todo"); - var todo_local = todo_resolveBodyResult.Item2; - if (!todo_resolveBodyResult.Item1) - { - return; - } + httpContext.Response.StatusCode = 400; + return; + } + var result = handler(todo_local!); + await GeneratedRouteBuilderExtensionsCore.ExecuteAsyncExplicit(result, httpContext); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(todo_local!); - await GeneratedRouteBuilderExtensionsCore.ExecuteAsyncExplicit(result, httpContext); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBody) + var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "Todo", "todo"); + var todo_local = todo_resolveBodyResult.Item2; + if (!todo_resolveBodyResult.Item1) + { + return; } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBody) - var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "Todo", "todo"); - var todo_local = todo_resolveBodyResult.Item2; - if (!todo_resolveBodyResult.Item1) - { - return; - } + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local!)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - if (wasParamCheckFailure) + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + PostVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_27( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), isOptional: true, contentTypes: GeneratedMetadataConstants.JsonContentType)); + PopulateMetadataForEndpoint>(methodInfo, options.EndpointBuilder); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::Microsoft.AspNetCore.Http.HttpResults.Ok (global::Microsoft.AspNetCore.Http.Generators.Tests.Todo? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; + return ValueTask.FromResult(Results.Empty); } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local!)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 27)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), isOptional: true, contentTypes: GeneratedMetadataConstants.JsonContentType)); - PopulateMetadataForEndpoint>(methodInfo, options.EndpointBuilder); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func>)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo?, IsOptional = True, IsParsable = False, IsArray = False, Source = JsonBody) + var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, true, "Todo?", "todo"); + var todo_local = todo_resolveBodyResult.Item2; + if (!todo_resolveBodyResult.Item1) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + return; } - async Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo?, IsOptional = True, IsParsable = False, IsArray = False, Source = JsonBody) - var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, true, "Todo?", "todo"); - var todo_local = todo_resolveBodyResult.Item2; - if (!todo_resolveBodyResult.Item1) - { - return; - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(todo_local); - await GeneratedRouteBuilderExtensionsCore.ExecuteAsyncExplicit(result, httpContext); + httpContext.Response.StatusCode = 400; + return; } + var result = handler(todo_local); + await GeneratedRouteBuilderExtensionsCore.ExecuteAsyncExplicit(result, httpContext); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo?, IsOptional = True, IsParsable = False, IsArray = False, Source = JsonBody) + var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, true, "Todo?", "todo"); + var todo_local = todo_resolveBodyResult.Item2; + if (!todo_resolveBodyResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo?, IsOptional = True, IsParsable = False, IsArray = False, Source = JsonBody) - var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, true, "Todo?", "todo"); - var todo_local = todo_resolveBodyResult.Item2; - if (!todo_resolveBodyResult.Item1) - { - return; - } + return; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + PostVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt index dd7e828f6225..4c27b89d771a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,123 +69,144 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - Task RequestHandler(HttpContext httpContext) + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Header) + var p_raw = httpContext.Request.Headers["p"]; + var p_temp = p_raw.ToArray(); + global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + for (var i = 0; i < p_temp.Length; i++) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Header) - var p_raw = httpContext.Request.Headers["p"]; - var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; - for (var i = 0; i < p_temp.Length; i++) + var element = p_temp[i]; + if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) { - var element = p_temp[i]; - if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) + if (!string.IsNullOrEmpty(element)) { - if (!string.IsNullOrEmpty(element)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); - wasParamCheckFailure = true; - } + logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); + wasParamCheckFailure = true; } - p_local[i] = parsed_element!; } + p_local[i] = parsed_element!; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Header) + var p_raw = httpContext.Request.Headers["p"]; + var p_temp = p_raw.ToArray(); + global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + for (var i = 0; i < p_temp.Length; i++) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Header) - var p_raw = httpContext.Request.Headers["p"]; - var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; - for (var i = 0; i < p_temp.Length; i++) + var element = p_temp[i]; + if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) { - var element = p_temp[i]; - if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) + if (!string.IsNullOrEmpty(element)) { - if (!string.IsNullOrEmpty(element)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); - wasParamCheckFailure = true; - } + logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); + wasParamCheckFailure = true; } - p_local[i] = parsed_element!; } + p_local[i] = parsed_element!; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt index 49f688148a48..fe64fcb619c3 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,97 +69,118 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = Header) + var p_raw = httpContext.Request.Headers["p"]; + var p_temp = p_raw.ToArray(); + string[] p_local = p_temp!; - Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = Header) - var p_raw = httpContext.Request.Headers["p"]; - var p_temp = p_raw.ToArray(); - string[] p_local = p_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = Header) - var p_raw = httpContext.Request.Headers["p"]; - var p_temp = p_raw.ToArray(); - string[] p_local = p_temp!; + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = Header) + var p_raw = httpContext.Request.Headers["p"]; + var p_temp = p_raw.ToArray(); + string[] p_local = p_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt index fb678ab02ec2..519ba8dde312 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,97 +69,118 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = Header) + var p_raw = httpContext.Request.Headers["p"]; + var p_temp = p_raw.ToArray(); + string[] p_local = p_temp!; - Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = Header) - var p_raw = httpContext.Request.Headers["p"]; - var p_temp = p_raw.ToArray(); - string[] p_local = p_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = Header) - var p_raw = httpContext.Request.Headers["p"]; - var p_temp = p_raw.ToArray(); - string[] p_local = p_temp!; + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = Header) + var p_raw = httpContext.Request.Headers["p"]; + var p_temp = p_raw.ToArray(); + string[] p_local = p_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt index 769fcced92f5..d4f7df046ef0 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,123 +69,144 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - Task RequestHandler(HttpContext httpContext) + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + var p_temp = p_raw.ToArray(); + global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + for (var i = 0; i < p_temp.Length; i++) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; - for (var i = 0; i < p_temp.Length; i++) + var element = p_temp[i]; + if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) { - var element = p_temp[i]; - if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) + if (!string.IsNullOrEmpty(element)) { - if (!string.IsNullOrEmpty(element)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); - wasParamCheckFailure = true; - } + logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); + wasParamCheckFailure = true; } - p_local[i] = parsed_element!; } + p_local[i] = parsed_element!; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + var p_temp = p_raw.ToArray(); + global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + for (var i = 0; i < p_temp.Length; i++) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; - for (var i = 0; i < p_temp.Length; i++) + var element = p_temp[i]; + if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) { - var element = p_temp[i]; - if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) + if (!string.IsNullOrEmpty(element)) { - if (!string.IsNullOrEmpty(element)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); - wasParamCheckFailure = true; - } + logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); + wasParamCheckFailure = true; } - p_local[i] = parsed_element!; } + p_local[i] = parsed_element!; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt index dcf0b92197ca..ee2a579a92be 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,96 +69,117 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.ToArray(); - string[] p_local = p_temp!; + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); - } + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + var p_temp = p_raw.ToArray(); + string[] p_local = p_temp!; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.ToArray(); - string[] p_local = p_temp!; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + var p_temp = p_raw.ToArray(); + string[] p_local = p_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt index 651b7d1bd675..3260e814c9c6 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,96 +69,117 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.ToArray(); - string[] p_local = p_temp!; + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); - } + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + var p_temp = p_raw.ToArray(); + string[] p_local = p_temp!; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.ToArray(); - string[] p_local = p_temp!; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + var p_temp = p_raw.ToArray(); + string[] p_local = p_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt index 4f594f144253..5b8e2bcd91fc 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt @@ -22,67 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func, global::System.String> handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func, global::System.String> handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - } } @@ -119,253 +69,280 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.TestService arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) - var svc_local = httpContext.RequestServices.GetRequiredService(); + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(svc_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); - } + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) + var svc_local = httpContext.RequestServices.GetRequiredService(); - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) - var svc_local = httpContext.RequestServices.GetRequiredService(); - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, svc_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(svc_local); + return httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 26)] = ( - (methodInfo, options) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func, global::System.String>)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) + var svc_local = httpContext.RequestServices.GetRequiredService(); + + if (wasParamCheckFailure) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument>(0)!)); - }, - options.EndpointBuilder, - handler.Method); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, svc_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: svc (Type = System.Collections.Generic.IEnumerable, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) - var svc_local = httpContext.RequestServices.GetRequiredService>(); + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(svc_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.Collections.Generic.IEnumerable arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + return ValueTask.FromResult(Results.Empty); } - return httpContext.Response.WriteAsync(result); - } + return ValueTask.FromResult(handler(ic.GetArgument>(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: svc (Type = System.Collections.Generic.IEnumerable, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) - var svc_local = httpContext.RequestServices.GetRequiredService>(); + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create>(httpContext, svc_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: svc (Type = System.Collections.Generic.IEnumerable, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) + var svc_local = httpContext.RequestServices.GetRequiredService>(); + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(svc_local); + return httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 27)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func, global::System.String>)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: svc (Type = System.Collections.Generic.IEnumerable, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) + var svc_local = httpContext.RequestServices.GetRequiredService>(); + + if (wasParamCheckFailure) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument>(1)!)); - }, - options.EndpointBuilder, - handler.Method); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create>(httpContext, svc_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService?, IsOptional = True, IsParsable = False, IsArray = False, Source = Service) - var svc_local = httpContext.RequestServices.GetService();; - // Endpoint Parameter: svcs (Type = System.Collections.Generic.IEnumerable, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) - var svcs_local = httpContext.RequestServices.GetRequiredService>(); + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(svc_local, svcs_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.TestService? arg0, global::System.Collections.Generic.IEnumerable arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + return ValueTask.FromResult(Results.Empty); } - return httpContext.Response.WriteAsync(result); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument>(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService?, IsOptional = True, IsParsable = False, IsArray = False, Source = Service) + var svc_local = httpContext.RequestServices.GetService();; + // Endpoint Parameter: svcs (Type = System.Collections.Generic.IEnumerable, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) + var svcs_local = httpContext.RequestServices.GetRequiredService>(); + + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService?, IsOptional = True, IsParsable = False, IsArray = False, Source = Service) - var svc_local = httpContext.RequestServices.GetService();; - // Endpoint Parameter: svcs (Type = System.Collections.Generic.IEnumerable, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) - var svcs_local = httpContext.RequestServices.GetRequiredService>(); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(svc_local, svcs_local); + return httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create>(httpContext, svc_local, svcs_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService?, IsOptional = True, IsParsable = False, IsArray = False, Source = Service) + var svc_local = httpContext.RequestServices.GetService();; + // Endpoint Parameter: svcs (Type = System.Collections.Generic.IEnumerable, IsOptional = False, IsParsable = False, IsArray = False, Source = Service) + var svcs_local = httpContext.RequestServices.GetRequiredService>(); + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create>(httpContext, svc_local, svcs_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt index b8746767aac6..ba04197d0e71 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,479 +69,520 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: queryValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) + var queryValue_raw = httpContext.Request.Query["queryValue"]; + if (StringValues.IsNullOrEmpty(queryValue_raw)) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "queryValue", "query string"); } + var queryValue_temp = (string?)queryValue_raw; + string queryValue_local = queryValue_temp!; - Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: queryValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) - var queryValue_raw = httpContext.Request.Query["queryValue"]; - if (StringValues.IsNullOrEmpty(queryValue_raw)) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "queryValue", "query string"); - } - var queryValue_temp = (string?)queryValue_raw; - string queryValue_local = queryValue_temp!; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(queryValue_local); + return httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(queryValue_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: queryValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) + var queryValue_raw = httpContext.Request.Query["queryValue"]; + if (StringValues.IsNullOrEmpty(queryValue_raw)) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "queryValue", "query string"); } + var queryValue_temp = (string?)queryValue_raw; + string queryValue_local = queryValue_temp!; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: queryValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) - var queryValue_raw = httpContext.Request.Query["queryValue"]; - if (StringValues.IsNullOrEmpty(queryValue_raw)) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "queryValue", "query string"); - } - var queryValue_temp = (string?)queryValue_raw; - string queryValue_local = queryValue_temp!; + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, queryValue_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - if (wasParamCheckFailure) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; + return ValueTask.FromResult(Results.Empty); } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, queryValue_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 26)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: headerValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Header) + var headerValue_raw = httpContext.Request.Headers["headerValue"]; + if (StringValues.IsNullOrEmpty(headerValue_raw)) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "headerValue", "header"); } + var headerValue_temp = (string?)headerValue_raw; + string headerValue_local = headerValue_temp!; - Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: headerValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Header) - var headerValue_raw = httpContext.Request.Headers["headerValue"]; - if (StringValues.IsNullOrEmpty(headerValue_raw)) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "headerValue", "header"); - } - var headerValue_temp = (string?)headerValue_raw; - string headerValue_local = headerValue_temp!; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(headerValue_local); + return httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(headerValue_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: headerValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Header) + var headerValue_raw = httpContext.Request.Headers["headerValue"]; + if (StringValues.IsNullOrEmpty(headerValue_raw)) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "headerValue", "header"); } + var headerValue_temp = (string?)headerValue_raw; + string headerValue_local = headerValue_temp!; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: headerValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Header) - var headerValue_raw = httpContext.Request.Headers["headerValue"]; - if (StringValues.IsNullOrEmpty(headerValue_raw)) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "headerValue", "header"); - } - var headerValue_temp = (string?)headerValue_raw; - string headerValue_local = headerValue_temp!; + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, headerValue_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - if (wasParamCheckFailure) + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; + return ValueTask.FromResult(Results.Empty); } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, headerValue_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 27)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: routeValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Route) + if (options?.RouteParameterNames?.Contains("routeValue", StringComparer.OrdinalIgnoreCase) != true) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + throw new InvalidOperationException($"'routeValue' is not a route parameter."); + } + var routeValue_raw = (string?)httpContext.Request.RouteValues["routeValue"]; + if (routeValue_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "routeValue", "route"); } + var routeValue_temp = (string?)routeValue_raw; + string routeValue_local = routeValue_temp!; - Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: routeValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Route) - if (options?.RouteParameterNames?.Contains("routeValue", StringComparer.OrdinalIgnoreCase) != true) - { - throw new InvalidOperationException($"'routeValue' is not a route parameter."); - } - var routeValue_raw = (string?)httpContext.Request.RouteValues["routeValue"]; - if (routeValue_raw == null) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "routeValue", "route"); - } - var routeValue_temp = (string?)routeValue_raw; - string routeValue_local = routeValue_temp!; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(routeValue_local!); + return httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(routeValue_local!); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: routeValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Route) + if (options?.RouteParameterNames?.Contains("routeValue", StringComparer.OrdinalIgnoreCase) != true) + { + throw new InvalidOperationException($"'routeValue' is not a route parameter."); } + var routeValue_raw = (string?)httpContext.Request.RouteValues["routeValue"]; + if (routeValue_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "routeValue", "route"); + } + var routeValue_temp = (string?)routeValue_raw; + string routeValue_local = routeValue_temp!; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: routeValue (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Route) - if (options?.RouteParameterNames?.Contains("routeValue", StringComparer.OrdinalIgnoreCase) != true) - { - throw new InvalidOperationException($"'routeValue' is not a route parameter."); - } - var routeValue_raw = (string?)httpContext.Request.RouteValues["routeValue"]; - if (routeValue_raw == null) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "routeValue", "route"); - } - var routeValue_temp = (string?)routeValue_raw; - string routeValue_local = routeValue_temp!; + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, routeValue_local!)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - if (wasParamCheckFailure) + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 28, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_28( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 28)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; + return ValueTask.FromResult(Results.Empty); } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, routeValue_local!)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 28)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 28)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var value_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("value", options?.RouteParameterNames); + + Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var value_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("value", options.RouteParameterNames); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: value (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = RouteOrQuery) + var value_raw = value_RouteOrQueryResolver(httpContext); + if (value_raw is StringValues { Count: 0 }) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "value", "route or query string"); } + var value_temp = (string?)value_raw; + string value_local = value_temp!; - Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: value (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = RouteOrQuery) - var value_raw = value_RouteOrQueryResolver(httpContext); - if (value_raw is StringValues { Count: 0 }) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "value", "route or query string"); - } - var value_temp = (string?)value_raw; - string value_local = value_temp!; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(value_local!); + return httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(value_local!); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: value (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = RouteOrQuery) + var value_raw = value_RouteOrQueryResolver(httpContext); + if (value_raw is StringValues { Count: 0 }) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "value", "route or query string"); } + var value_temp = (string?)value_raw; + string value_local = value_temp!; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: value (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = RouteOrQuery) - var value_raw = value_RouteOrQueryResolver(httpContext); - if (value_raw is StringValues { Count: 0 }) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "value", "route or query string"); - } - var value_temp = (string?)value_raw; - string value_local = value_temp!; + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, value_local!)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - if (wasParamCheckFailure) + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 29, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_29( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 29)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; + return ValueTask.FromResult(Results.Empty); } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, value_local!)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 29)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 29)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var value_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("value", options?.RouteParameterNames); + + Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var value_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("value", options.RouteParameterNames); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: value (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = RouteOrQuery) + var value_raw = value_RouteOrQueryResolver(httpContext); + if (value_raw is StringValues { Count: 0 }) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "value", "route or query string"); } + var value_temp = (string?)value_raw; + string value_local = value_temp!; - Task RequestHandler(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: value (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = RouteOrQuery) - var value_raw = value_RouteOrQueryResolver(httpContext); - if (value_raw is StringValues { Count: 0 }) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "value", "route or query string"); - } - var value_temp = (string?)value_raw; - string value_local = value_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(value_local!); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(value_local!); + return httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: value (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = RouteOrQuery) + var value_raw = value_RouteOrQueryResolver(httpContext); + if (value_raw is StringValues { Count: 0 }) { - var wasParamCheckFailure = false; - // Endpoint Parameter: value (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = RouteOrQuery) - var value_raw = value_RouteOrQueryResolver(httpContext); - if (value_raw is StringValues { Count: 0 }) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "value", "route or query string"); - } - var value_temp = (string?)value_raw; - string value_local = value_temp!; + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "value", "route or query string"); + } + var value_temp = (string?)value_raw; + string value_local = value_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, value_local!)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, value_local!)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt index 9e35af5a26de..1b86253d53a4 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,124 +69,145 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var p_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("p", options.RouteParameterNames); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } - - Task RequestHandler(HttpContext httpContext) + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var p_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("p", options?.RouteParameterNames); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = RouteOrQuery) + var p_raw = p_RouteOrQueryResolver(httpContext); + var p_temp = p_raw.ToArray(); + global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + for (var i = 0; i < p_temp.Length; i++) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = RouteOrQuery) - var p_raw = p_RouteOrQueryResolver(httpContext); - var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; - for (var i = 0; i < p_temp.Length; i++) + var element = p_temp[i]; + if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) { - var element = p_temp[i]; - if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) + if (!string.IsNullOrEmpty(element)) { - if (!string.IsNullOrEmpty(element)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); - wasParamCheckFailure = true; - } + logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); + wasParamCheckFailure = true; } - p_local[i] = parsed_element!; } + p_local[i] = parsed_element!; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local!); - return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local!); + return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = RouteOrQuery) + var p_raw = p_RouteOrQueryResolver(httpContext); + var p_temp = p_raw.ToArray(); + global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + for (var i = 0; i < p_temp.Length; i++) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = RouteOrQuery) - var p_raw = p_RouteOrQueryResolver(httpContext); - var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; - for (var i = 0; i < p_temp.Length; i++) + var element = p_temp[i]; + if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) { - var element = p_temp[i]; - if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(element!, CultureInfo.InvariantCulture, out var parsed_element)) + if (!string.IsNullOrEmpty(element)) { - if (!string.IsNullOrEmpty(element)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); - wasParamCheckFailure = true; - } + logOrThrowExceptionHelper.ParameterBindingFailed("ParsableTodo[]", "p", element); + wasParamCheckFailure = true; } - p_local[i] = parsed_element!; } + p_local[i] = parsed_element!; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local!)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local!)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt index c535668036c6..9e26b5f9b207 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,134 +69,142 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String?[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String?[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt index c535668036c6..9e26b5f9b207 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,134 +69,142 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String?[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String?[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt index c535668036c6..9e26b5f9b207 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,134 +69,142 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String?[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String?[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt index 9654865388b9..839821418f0d 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,134 +69,142 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt index 6486d2e8c1fc..4709bfb0befa 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - PostVerb, - filePath, - lineNumber); } - } } @@ -89,140 +69,153 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var serviceProviderIsService = serviceProvider.GetRequiredService(); + var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { + (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo)), + (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.TestService)), + }; + foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo)), - (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.TestService)), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + if (!serviceProviderIsService.IsService(type)) { - if (!serviceProviderIsService.IsService(type)) - { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; - } + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); + break; } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + } + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.Todo arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.TestService arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serviceProviderIsService = serviceProvider?.GetService(); - var todo_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "Todo", "todo", serviceProviderIsService); - var svc_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "TestService", "svc", serviceProviderIsService); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandler(HttpContext httpContext) + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serviceProviderIsService = serviceProvider?.GetService(); + var todo_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "Todo", "todo", serviceProviderIsService); + var svc_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "TestService", "svc", serviceProviderIsService); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var todo_resolveJsonBodyOrServiceResult = await todo_JsonBodyOrServiceResolver(httpContext, false); + var todo_local = todo_resolveJsonBodyOrServiceResult.Item2; + if (!todo_resolveJsonBodyOrServiceResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var todo_resolveJsonBodyOrServiceResult = await todo_JsonBodyOrServiceResolver(httpContext, false); - var todo_local = todo_resolveJsonBodyOrServiceResult.Item2; - if (!todo_resolveJsonBodyOrServiceResult.Item1) - { - return; - } - // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var svc_resolveJsonBodyOrServiceResult = await svc_JsonBodyOrServiceResolver(httpContext, false); - var svc_local = svc_resolveJsonBodyOrServiceResult.Item2; - if (!svc_resolveJsonBodyOrServiceResult.Item1) - { - return; - } + return; + } + // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var svc_resolveJsonBodyOrServiceResult = await svc_JsonBodyOrServiceResolver(httpContext, false); + var svc_local = svc_resolveJsonBodyOrServiceResult.Item2; + if (!svc_resolveJsonBodyOrServiceResult.Item1) + { + return; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(todo_local!, svc_local!); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(todo_local!, svc_local!); + await httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var todo_resolveJsonBodyOrServiceResult = await todo_JsonBodyOrServiceResolver(httpContext, false); + var todo_local = todo_resolveJsonBodyOrServiceResult.Item2; + if (!todo_resolveJsonBodyOrServiceResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var todo_resolveJsonBodyOrServiceResult = await todo_JsonBodyOrServiceResolver(httpContext, false); - var todo_local = todo_resolveJsonBodyOrServiceResult.Item2; - if (!todo_resolveJsonBodyOrServiceResult.Item1) - { - return; - } - // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var svc_resolveJsonBodyOrServiceResult = await svc_JsonBodyOrServiceResolver(httpContext, false); - var svc_local = svc_resolveJsonBodyOrServiceResult.Item2; - if (!svc_resolveJsonBodyOrServiceResult.Item1) - { - return; - } + return; + } + // Endpoint Parameter: svc (Type = Microsoft.AspNetCore.Http.Generators.Tests.TestService, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var svc_resolveJsonBodyOrServiceResult = await svc_JsonBodyOrServiceResolver(httpContext, false); + var svc_local = svc_resolveJsonBodyOrServiceResult.Item2; + if (!svc_resolveJsonBodyOrServiceResult.Item1) + { + return; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local!, svc_local!)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local!, svc_local!)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + PostVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt index bfb09e9f7f35..1b6eed872714 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,97 +69,110 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpRequest arg0, global::Microsoft.AspNetCore.Http.HttpResponse arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var req_local = httpContext.Request; - var res_local = httpContext.Response; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(req_local, res_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); - } + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var req_local = httpContext.Request; + var res_local = httpContext.Response; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var req_local = httpContext.Request; - var res_local = httpContext.Response; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(req_local, res_local); + return httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local, res_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var req_local = httpContext.Request; + var res_local = httpContext.Response; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local, res_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt index 99e900ce4764..8a1fa3601b3b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,131 +69,144 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String arg0, global::System.String arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - Task RequestHandler(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p1 (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) + var p1_raw = httpContext.Request.Query["p1"]; + if (StringValues.IsNullOrEmpty(p1_raw)) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p1 (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) - var p1_raw = httpContext.Request.Query["p1"]; - if (StringValues.IsNullOrEmpty(p1_raw)) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "p1", "query string"); - } - var p1_temp = (string?)p1_raw; - string p1_local = p1_temp!; - // Endpoint Parameter: p2 (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) - var p2_raw = httpContext.Request.Query["p2"]; - if (StringValues.IsNullOrEmpty(p2_raw)) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "p2", "query string"); - } - var p2_temp = (string?)p2_raw; - string p2_local = p2_temp!; + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "p1", "query string"); + } + var p1_temp = (string?)p1_raw; + string p1_local = p1_temp!; + // Endpoint Parameter: p2 (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) + var p2_raw = httpContext.Request.Query["p2"]; + if (StringValues.IsNullOrEmpty(p2_raw)) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "p2", "query string"); + } + var p2_temp = (string?)p2_raw; + string p2_local = p2_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p1_local, p2_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p1_local, p2_local); + return httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p1 (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) + var p1_raw = httpContext.Request.Query["p1"]; + if (StringValues.IsNullOrEmpty(p1_raw)) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p1 (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) - var p1_raw = httpContext.Request.Query["p1"]; - if (StringValues.IsNullOrEmpty(p1_raw)) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "p1", "query string"); - } - var p1_temp = (string?)p1_raw; - string p1_local = p1_temp!; - // Endpoint Parameter: p2 (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) - var p2_raw = httpContext.Request.Query["p2"]; - if (StringValues.IsNullOrEmpty(p2_raw)) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "p2", "query string"); - } - var p2_temp = (string?)p2_raw; - string p2_local = p2_temp!; + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "p1", "query string"); + } + var p1_temp = (string?)p1_raw; + string p1_local = p1_temp!; + // Endpoint Parameter: p2 (Type = string, IsOptional = False, IsParsable = False, IsArray = False, Source = Query) + var p2_raw = httpContext.Request.Query["p2"]; + if (StringValues.IsNullOrEmpty(p2_raw)) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("string", "p2", "query string"); + } + var p2_temp = (string?)p2_raw; + string p2_local = p2_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p1_local, p2_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p1_local, p2_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt index acbfbab82d85..442cb054a677 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,91 +69,104 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler()); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler()); + }, + options.EndpointBuilder, + handler.Method); + } + - Task RequestHandler(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(); + return httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt index acbfbab82d85..442cb054a677 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,91 +69,104 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler()); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler()); + }, + options.EndpointBuilder, + handler.Method); + } + - Task RequestHandler(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(); + return httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt index 53dbe79f93d5..b27c5510d086 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,86 +69,107 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::Microsoft.AspNetCore.Http.Generators.Tests.Todo () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler()); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler()); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo)); - Task RequestHandler(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(); - return GeneratedRouteBuilderExtensionsCore.WriteToResponseAsync(result, httpContext, jsonTypeInfo); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(); + return GeneratedRouteBuilderExtensionsCore.WriteToResponseAsync(result, httpContext, jsonTypeInfo); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt index 2750e53d69da..25b842275978 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,83 +69,103 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::Microsoft.AspNetCore.Http.HttpResults.ValidationProblem () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler()); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler()); + }, + options.EndpointBuilder, + handler.Method); + } + - Task RequestHandler(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(); - return GeneratedRouteBuilderExtensionsCore.ExecuteAsyncExplicit(result, httpContext); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + var result = handler(); + return GeneratedRouteBuilderExtensionsCore.ExecuteAsyncExplicit(result, httpContext); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt index 1e4d6ed1112f..1dcc34184bb7 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Action handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,83 +69,103 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, void () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Action)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - handler(); return ValueTask.FromResult(Results.Empty); - }, - options.EndpointBuilder, - handler.Method); - } - - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; } handler(); + return ValueTask.FromResult(Results.Empty); + }, + options.EndpointBuilder, + handler.Method); + } + + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; return Task.CompletedTask; } + handler(); + return Task.CompletedTask; + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt index 22c5e13b2535..611e9dfede54 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,129 +69,142 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - Task RequestHandler(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo, IsOptional = False, IsParsable = True, IsArray = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo, IsOptional = False, IsParsable = True, IsArray = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("TryParseTodo", "p", "query string"); + } + var p_temp = (string?)p_raw; + if (!global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo.TryParse(p_temp!, out var p_parsed_temp)) + { + if (!string.IsNullOrEmpty(p_temp)) { + logOrThrowExceptionHelper.ParameterBindingFailed("TryParseTodo", "p", p_temp); wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("TryParseTodo", "p", "query string"); - } - var p_temp = (string?)p_raw; - if (!global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo.TryParse(p_temp!, out var p_parsed_temp)) - { - if (!string.IsNullOrEmpty(p_temp)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("TryParseTodo", "p", p_temp); - wasParamCheckFailure = true; - } } - global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo p_local = p_parsed_temp!; + } + global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo p_local = p_parsed_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo, IsOptional = False, IsParsable = True, IsArray = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo, IsOptional = False, IsParsable = True, IsArray = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("TryParseTodo", "p", "query string"); + } + var p_temp = (string?)p_raw; + if (!global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo.TryParse(p_temp!, out var p_parsed_temp)) + { + if (!string.IsNullOrEmpty(p_temp)) { + logOrThrowExceptionHelper.ParameterBindingFailed("TryParseTodo", "p", p_temp); wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("TryParseTodo", "p", "query string"); - } - var p_temp = (string?)p_raw; - if (!global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo.TryParse(p_temp!, out var p_parsed_temp)) - { - if (!string.IsNullOrEmpty(p_temp)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("TryParseTodo", "p", p_temp); - wasParamCheckFailure = true; - } } - global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo p_local = p_parsed_temp!; + } + global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo p_local = p_parsed_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt index 8ce33a2fc917..b47585bdc4ae 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,129 +69,142 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - Task RequestHandler(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus, IsOptional = False, IsParsable = True, IsArray = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus, IsOptional = False, IsParsable = True, IsArray = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("TodoStatus", "p", "query string"); + } + var p_temp = (string?)p_raw; + if (!Enum.TryParse(p_temp!, out var p_parsed_temp)) + { + if (!string.IsNullOrEmpty(p_temp)) { + logOrThrowExceptionHelper.ParameterBindingFailed("TodoStatus", "p", p_temp); wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("TodoStatus", "p", "query string"); - } - var p_temp = (string?)p_raw; - if (!Enum.TryParse(p_temp!, out var p_parsed_temp)) - { - if (!string.IsNullOrEmpty(p_temp)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("TodoStatus", "p", p_temp); - wasParamCheckFailure = true; - } } - global::Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus p_local = p_parsed_temp!; + } + global::Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus p_local = p_parsed_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus, IsOptional = False, IsParsable = True, IsArray = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus, IsOptional = False, IsParsable = True, IsArray = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("TodoStatus", "p", "query string"); + } + var p_temp = (string?)p_raw; + if (!Enum.TryParse(p_temp!, out var p_parsed_temp)) + { + if (!string.IsNullOrEmpty(p_temp)) { + logOrThrowExceptionHelper.ParameterBindingFailed("TodoStatus", "p", p_temp); wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("TodoStatus", "p", "query string"); - } - var p_temp = (string?)p_raw; - if (!Enum.TryParse(p_temp!, out var p_parsed_temp)) - { - if (!string.IsNullOrEmpty(p_temp)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("TodoStatus", "p", p_temp); - wasParamCheckFailure = true; - } } - global::Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus p_local = p_parsed_temp!; + } + global::Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus p_local = p_parsed_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt index 9825fa84f052..2a728e60002a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - } } @@ -89,103 +69,116 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String? arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?, IsOptional = True, IsParsable = False, IsArray = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.Count > 0 ? (string?)p_raw : null; - string p_local = p_temp!; + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(p_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); - } + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?, IsOptional = True, IsParsable = False, IsArray = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + var p_temp = p_raw.Count > 0 ? (string?)p_raw : null; + string p_local = p_temp!; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string?, IsOptional = True, IsParsable = False, IsArray = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.Count > 0 ? (string?)p_raw : null; - string p_local = p_temp!; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string?, IsOptional = True, IsParsable = False, IsArray = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + var p_temp = p_raw.Count > 0 ? (string?)p_raw : null; + string p_local = p_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt index 43f428d4bc62..e5b6afcfaaf9 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Action handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - PostVerb, - filePath, - lineNumber); } - } } @@ -89,119 +69,139 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var serviceProviderIsService = serviceProvider.GetRequiredService(); + var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { + (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter)), + }; + foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter)), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + if (!serviceProviderIsService.IsService(type)) { - if (!serviceProviderIsService.IsService(type)) - { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; - } + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); + break; } - var parameterInfos = methodInfo.GetParameters(); - var x_ParameterInfo = parameterInfos[0]; - PopulateMetadataForParameter(x_ParameterInfo, options.EndpointBuilder); - PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + } + var parameterInfos = methodInfo.GetParameters(); + var x_ParameterInfo = parameterInfos[0]; + PopulateMetadataForParameter(x_ParameterInfo, options.EndpointBuilder); + PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Action)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serviceProviderIsService = serviceProvider?.GetService(); - var x_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "CustomMetadataEmitter", "x", serviceProviderIsService); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); - }, - options.EndpointBuilder, - handler.Method); - } + } + handler(ic.GetArgument(0)!); + return ValueTask.FromResult(Results.Empty); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandler(HttpContext httpContext) + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serviceProviderIsService = serviceProvider?.GetService(); + var x_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "CustomMetadataEmitter", "x", serviceProviderIsService); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: x (Type = Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var x_resolveJsonBodyOrServiceResult = await x_JsonBodyOrServiceResolver(httpContext, false); + var x_local = x_resolveJsonBodyOrServiceResult.Item2; + if (!x_resolveJsonBodyOrServiceResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: x (Type = Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var x_resolveJsonBodyOrServiceResult = await x_JsonBodyOrServiceResolver(httpContext, false); - var x_local = x_resolveJsonBodyOrServiceResult.Item2; - if (!x_resolveJsonBodyOrServiceResult.Item1) - { - return; - } + return; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - handler(x_local!); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; } + handler(x_local!); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: x (Type = Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var x_resolveJsonBodyOrServiceResult = await x_JsonBodyOrServiceResolver(httpContext, false); + var x_local = x_resolveJsonBodyOrServiceResult.Item2; + if (!x_resolveJsonBodyOrServiceResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: x (Type = Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var x_resolveJsonBodyOrServiceResult = await x_JsonBodyOrServiceResolver(httpContext, false); - var x_local = x_resolveJsonBodyOrServiceResult.Item2; - if (!x_resolveJsonBodyOrServiceResult.Item1) - { - return; - } + return; + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, x_local!)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, x_local!)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + PostVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt index 778a2a41e5eb..2d578a603942 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt @@ -22,38 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Collections.Generic.IEnumerable httpMethods, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - httpMethods, - filePath, - lineNumber); } - } } @@ -90,140 +69,141 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Collections.Generic.IEnumerable httpMethods, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p_local); + await httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + httpMethods, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt index 778a2a41e5eb..2d578a603942 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt @@ -22,38 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Collections.Generic.IEnumerable httpMethods, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - httpMethods, - filePath, - lineNumber); } - } } @@ -90,140 +69,141 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Collections.Generic.IEnumerable httpMethods, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p_local); + await httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + httpMethods, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index 778a2a41e5eb..2d578a603942 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -22,38 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Collections.Generic.IEnumerable httpMethods, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - httpMethods, - filePath, - lineNumber); } - } } @@ -90,140 +69,141 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Collections.Generic.IEnumerable httpMethods, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p_local); + await httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + httpMethods, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index 778a2a41e5eb..2d578a603942 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -22,38 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Collections.Generic.IEnumerable httpMethods, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - httpMethods, - filePath, - lineNumber); } - } } @@ -90,140 +69,141 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Collections.Generic.IEnumerable httpMethods, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p_local); + await httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + httpMethods, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index 95b3d720d8af..e8e33bf39a43 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - PostVerb, - filePath, - lineNumber); } - } } @@ -89,140 +69,140 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(p_local); + await httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + PostVerb, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt index 5de4e1cf285e..c13fc9f5851b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - PostVerb, - filePath, - lineNumber); } - } } @@ -89,134 +69,142 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Int32 (global::System.String[] arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var serviceProviderIsService = serviceProvider.GetRequiredService(); - var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::System.String[])), - }; - foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - if (!serviceProviderIsService.IsService(type)) + if (ic.HttpContext.Response.StatusCode == 400) { - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: type, isOptional: isOptional, contentTypes: GeneratedMetadataConstants.JsonContentType)); - break; + return ValueTask.FromResult(Results.Empty); } - } - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + + async Task RequestHandler(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; } - - async Task RequestHandler(HttpContext httpContext) + else { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; return; } - var result = handler(p_local); - await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; - if (options.DisableInferBodyFromParameters) - { - var p_raw = httpContext.Request.Query["p"]; - p_local = p_raw!; - } - else - { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); - p_local = p_resolveBodyResult.Item2!; - if (!p_resolveBodyResult.Item1) - { - return; - } - } + httpContext.Response.StatusCode = 400; + return; + } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); + } - if (wasParamCheckFailure) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) + global::System.String[] p_local = null!; + if (options.DisableInferBodyFromParameters) + { + var p_raw = httpContext.Request.Query["p"]; + p_local = p_raw!; + } + else + { + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + p_local = p_resolveBodyResult.Item2!; + if (!p_resolveBodyResult.Item1) { - httpContext.Response.StatusCode = 400; + return; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + PostVerb, + populateMetadata, + createRequestDelegate); + } + - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt index a5d31fcc54bd..3d0b4dcbb29a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt @@ -22,67 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func> handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func> handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - } } @@ -119,294 +69,328 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler()); - }, - options.EndpointBuilder, - handler.Method); - } - - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + return ValueTask.FromResult(Results.Empty); } - return httpContext.Response.WriteAsync(result); - } + return ValueTask.FromResult(handler()); + }, + options.EndpointBuilder, + handler.Method); + } + - async Task RequestHandlerFiltered(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(); + return httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 26)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler()); - }, - options.EndpointBuilder, - handler.Method); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - Task RequestHandler(HttpContext httpContext) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; + return ValueTask.FromResult(Results.Empty); } - var result = handler(); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); - } + return ValueTask.FromResult(handler()); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(); + return httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 27)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func>)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(async ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return (object?)Results.Empty; - } - var result = await handler(); - return (object?)result; - }, - options.EndpointBuilder, - handler.Method); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - async Task RequestHandler(HttpContext httpContext) +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Threading.Tasks.Task () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(async ic => { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; - return; + return (object?)Results.Empty; } var result = await handler(); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); - } + return (object?)result; + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = await handler(); + await httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 28)] = ( - (methodInfo, options) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 28)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func>)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(async ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return (object?)Results.Empty; - } - var result = await handler(); - return (object?)result; - }, - options.EndpointBuilder, - handler.Method); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - async Task RequestHandler(HttpContext httpContext) + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 28, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_28( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 28)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.Threading.Tasks.ValueTask () => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(async ic => { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.StatusCode = 400; - return; + return (object?)Results.Empty; } var result = await handler(); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + return (object?)result; + }, + options.EndpointBuilder, + handler.Method); + } + + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = await handler(); + await httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt index e6c89700f015..38f70812c409 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt @@ -22,67 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - } } @@ -119,239 +69,266 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 25)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpRequest arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var req_local = httpContext.Request; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(req_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - return httpContext.Response.WriteAsync(result); - } + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var req_local = httpContext.Request; - async Task RequestHandlerFiltered(HttpContext httpContext) + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var req_local = httpContext.Request; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(req_local); + return httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 26)] = ( - (methodInfo, options) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + var req_local = httpContext.Request; + + if (wasParamCheckFailure) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var res_local = httpContext.Response; + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(res_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 26)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpResponse arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + return ValueTask.FromResult(Results.Empty); } - return httpContext.Response.WriteAsync(result); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var res_local = httpContext.Response; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, res_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var res_local = httpContext.Response; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(res_local); + return httpContext.Response.WriteAsync(result); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 27)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + async Task RequestHandlerFiltered(HttpContext httpContext) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - - if (options.EndpointBuilder.FilterFactories.Count > 0) + var wasParamCheckFailure = false; + var res_local = httpContext.Response; + + if (wasParamCheckFailure) { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => - { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); - }, - options.EndpointBuilder, - handler.Method); + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, res_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - var req_local = httpContext.Request; - var res_local = httpContext.Response; + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - var result = handler(req_local, res_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpRequest arg0, global::Microsoft.AspNetCore.Http.HttpResponse arg1) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) + { + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + { + if (ic.HttpContext.Response.StatusCode == 400) { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + return ValueTask.FromResult(Results.Empty); } - return httpContext.Response.WriteAsync(result); - } + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var req_local = httpContext.Request; + var res_local = httpContext.Response; + + if (wasParamCheckFailure) { - var wasParamCheckFailure = false; - var req_local = httpContext.Request; - var res_local = httpContext.Response; + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(req_local, res_local); + return httpContext.Response.WriteAsync(result); + } - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local, res_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var req_local = httpContext.Request; + var res_local = httpContext.Response; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local, res_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt index 0c1e0ff39d18..9a883ac2babe 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt @@ -22,37 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Action handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - PostVerb, - filePath, - lineNumber); } - } } @@ -89,187 +69,207 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 29, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_29( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 29)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 29)); - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.FormFileContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 29)); + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.FormFileContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.IFormFile arg1, global::Microsoft.AspNetCore.Http.IFormFileCollection arg2, global::Microsoft.AspNetCore.Http.IFormCollection arg3, global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord arg4) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Action)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - handler(ic.GetArgument(0)!, ic.GetArgument(1)!, ic.GetArgument(2)!, ic.GetArgument(3)!, ic.GetArgument(4)!); return ValueTask.FromResult(Results.Empty); - }, - options.EndpointBuilder, - handler.Method); - } + } + handler(ic.GetArgument(0)!, ic.GetArgument(1)!, ic.GetArgument(2)!, ic.GetArgument(3)!, ic.GetArgument(4)!); + return ValueTask.FromResult(Results.Empty); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - async Task RequestHandler(HttpContext httpContext) + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + // Endpoint Parameter: file (Type = Microsoft.AspNetCore.Http.IFormFile, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) + var file_resolveFormResult = await GeneratedRouteBuilderExtensionsCore.TryResolveFormAsync(httpContext, logOrThrowExceptionHelper, "IFormFile", "file"); + if (!file_resolveFormResult.Item1) { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - // Endpoint Parameter: file (Type = Microsoft.AspNetCore.Http.IFormFile, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) - var file_resolveFormResult = await GeneratedRouteBuilderExtensionsCore.TryResolveFormAsync(httpContext, logOrThrowExceptionHelper, "IFormFile", "file"); - if (!file_resolveFormResult.Item1) - { - return; - } - var file_raw = httpContext.Request.Form.Files["file"]; - if (file_raw == null) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormFile", "file", "form"); - } - var file_temp = file_raw; - global::Microsoft.AspNetCore.Http.IFormFile file_local = file_temp!; - // Endpoint Parameter: fileCollection (Type = Microsoft.AspNetCore.Http.IFormFileCollection, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) - var fileCollection_raw = httpContext.Request.Form.Files; - if (fileCollection_raw == null) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormFileCollection", "fileCollection", "form"); - } - var fileCollection_temp = fileCollection_raw; - global::Microsoft.AspNetCore.Http.IFormFileCollection fileCollection_local = fileCollection_temp!; - // Endpoint Parameter: collection (Type = Microsoft.AspNetCore.Http.IFormCollection, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) - var collection_raw = httpContext.Request.Form; - if (collection_raw == null) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormCollection", "collection", "form"); - } - var collection_temp = collection_raw; - global::Microsoft.AspNetCore.Http.IFormCollection collection_local = collection_temp!; - // Endpoint Parameter: tryParseRecord (Type = Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord, IsOptional = False, IsParsable = True, IsArray = False, Source = FormBody) - var tryParseRecord_raw = (string?)httpContext.Request.Form["tryParseRecord"]; - if (tryParseRecord_raw == null) + return; + } + var file_raw = httpContext.Request.Form.Files["file"]; + if (file_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormFile", "file", "form"); + } + var file_temp = file_raw; + global::Microsoft.AspNetCore.Http.IFormFile file_local = file_temp!; + // Endpoint Parameter: fileCollection (Type = Microsoft.AspNetCore.Http.IFormFileCollection, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) + var fileCollection_raw = httpContext.Request.Form.Files; + if (fileCollection_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormFileCollection", "fileCollection", "form"); + } + var fileCollection_temp = fileCollection_raw; + global::Microsoft.AspNetCore.Http.IFormFileCollection fileCollection_local = fileCollection_temp!; + // Endpoint Parameter: collection (Type = Microsoft.AspNetCore.Http.IFormCollection, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) + var collection_raw = httpContext.Request.Form; + if (collection_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormCollection", "collection", "form"); + } + var collection_temp = collection_raw; + global::Microsoft.AspNetCore.Http.IFormCollection collection_local = collection_temp!; + // Endpoint Parameter: tryParseRecord (Type = Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord, IsOptional = False, IsParsable = True, IsArray = False, Source = FormBody) + var tryParseRecord_raw = (string?)httpContext.Request.Form["tryParseRecord"]; + if (tryParseRecord_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyTryParseRecord", "tryParseRecord", "form"); + } + var tryParseRecord_temp = tryParseRecord_raw; + if (!global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord.TryParse(tryParseRecord_temp!, out var tryParseRecord_parsed_temp)) + { + if (!string.IsNullOrEmpty(tryParseRecord_temp)) { + logOrThrowExceptionHelper.ParameterBindingFailed("MyTryParseRecord", "tryParseRecord", tryParseRecord_temp); wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyTryParseRecord", "tryParseRecord", "form"); } - var tryParseRecord_temp = tryParseRecord_raw; - if (!global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord.TryParse(tryParseRecord_temp!, out var tryParseRecord_parsed_temp)) - { - if (!string.IsNullOrEmpty(tryParseRecord_temp)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("MyTryParseRecord", "tryParseRecord", tryParseRecord_temp); - wasParamCheckFailure = true; - } - } - global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord tryParseRecord_local = tryParseRecord_parsed_temp!; + } + global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord tryParseRecord_local = tryParseRecord_parsed_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - handler(httpContext_local, file_local!, fileCollection_local!, collection_local!, tryParseRecord_local!); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; } + handler(httpContext_local, file_local!, fileCollection_local!, collection_local!, tryParseRecord_local!); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + var httpContext_local = httpContext; + // Endpoint Parameter: file (Type = Microsoft.AspNetCore.Http.IFormFile, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) + var file_resolveFormResult = await GeneratedRouteBuilderExtensionsCore.TryResolveFormAsync(httpContext, logOrThrowExceptionHelper, "IFormFile", "file"); + if (!file_resolveFormResult.Item1) { - var wasParamCheckFailure = false; - var httpContext_local = httpContext; - // Endpoint Parameter: file (Type = Microsoft.AspNetCore.Http.IFormFile, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) - var file_resolveFormResult = await GeneratedRouteBuilderExtensionsCore.TryResolveFormAsync(httpContext, logOrThrowExceptionHelper, "IFormFile", "file"); - if (!file_resolveFormResult.Item1) - { - return; - } - var file_raw = httpContext.Request.Form.Files["file"]; - if (file_raw == null) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormFile", "file", "form"); - } - var file_temp = file_raw; - global::Microsoft.AspNetCore.Http.IFormFile file_local = file_temp!; - // Endpoint Parameter: fileCollection (Type = Microsoft.AspNetCore.Http.IFormFileCollection, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) - var fileCollection_raw = httpContext.Request.Form.Files; - if (fileCollection_raw == null) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormFileCollection", "fileCollection", "form"); - } - var fileCollection_temp = fileCollection_raw; - global::Microsoft.AspNetCore.Http.IFormFileCollection fileCollection_local = fileCollection_temp!; - // Endpoint Parameter: collection (Type = Microsoft.AspNetCore.Http.IFormCollection, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) - var collection_raw = httpContext.Request.Form; - if (collection_raw == null) - { - wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormCollection", "collection", "form"); - } - var collection_temp = collection_raw; - global::Microsoft.AspNetCore.Http.IFormCollection collection_local = collection_temp!; - // Endpoint Parameter: tryParseRecord (Type = Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord, IsOptional = False, IsParsable = True, IsArray = False, Source = FormBody) - var tryParseRecord_raw = (string?)httpContext.Request.Form["tryParseRecord"]; - if (tryParseRecord_raw == null) + return; + } + var file_raw = httpContext.Request.Form.Files["file"]; + if (file_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormFile", "file", "form"); + } + var file_temp = file_raw; + global::Microsoft.AspNetCore.Http.IFormFile file_local = file_temp!; + // Endpoint Parameter: fileCollection (Type = Microsoft.AspNetCore.Http.IFormFileCollection, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) + var fileCollection_raw = httpContext.Request.Form.Files; + if (fileCollection_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormFileCollection", "fileCollection", "form"); + } + var fileCollection_temp = fileCollection_raw; + global::Microsoft.AspNetCore.Http.IFormFileCollection fileCollection_local = fileCollection_temp!; + // Endpoint Parameter: collection (Type = Microsoft.AspNetCore.Http.IFormCollection, IsOptional = False, IsParsable = False, IsArray = False, Source = FormBody) + var collection_raw = httpContext.Request.Form; + if (collection_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("IFormCollection", "collection", "form"); + } + var collection_temp = collection_raw; + global::Microsoft.AspNetCore.Http.IFormCollection collection_local = collection_temp!; + // Endpoint Parameter: tryParseRecord (Type = Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord, IsOptional = False, IsParsable = True, IsArray = False, Source = FormBody) + var tryParseRecord_raw = (string?)httpContext.Request.Form["tryParseRecord"]; + if (tryParseRecord_raw == null) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("MyTryParseRecord", "tryParseRecord", "form"); + } + var tryParseRecord_temp = tryParseRecord_raw; + if (!global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord.TryParse(tryParseRecord_temp!, out var tryParseRecord_parsed_temp)) + { + if (!string.IsNullOrEmpty(tryParseRecord_temp)) { + logOrThrowExceptionHelper.ParameterBindingFailed("MyTryParseRecord", "tryParseRecord", tryParseRecord_temp); wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("MyTryParseRecord", "tryParseRecord", "form"); } - var tryParseRecord_temp = tryParseRecord_raw; - if (!global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord.TryParse(tryParseRecord_temp!, out var tryParseRecord_parsed_temp)) - { - if (!string.IsNullOrEmpty(tryParseRecord_temp)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("MyTryParseRecord", "tryParseRecord", tryParseRecord_temp); - wasParamCheckFailure = true; - } - } - global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord tryParseRecord_local = tryParseRecord_parsed_temp!; + } + global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord tryParseRecord_local = tryParseRecord_parsed_temp!; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, file_local!, fileCollection_local!, collection_local!, tryParseRecord_local!)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, file_local!, fileCollection_local!, collection_local!, tryParseRecord_local!)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + PostVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt index 1e121483c243..cbc42622350b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt @@ -22,97 +22,17 @@ namespace Microsoft.AspNetCore.Builder Line = line; } } +} - // This class needs to be internal so that the compiled application - // has access to the strongly-typed endpoint definitions that are - // generated by the compiler so that they will be favored by - // overload resolution and opt the runtime in to the code generated - // implementation produced here. +namespace System.Runtime.CompilerServices +{ %GENERATEDCODEATTRIBUTE% - internal static class GenerateRouteBuilderEndpoints + [AttributeUsage(AttributeTargets.Method)] + file sealed class InterceptsLocationAttribute : Attribute { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Action handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Action handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) + public InterceptsLocationAttribute(string filePath, int line, int column) { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Action handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Func handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - PostVerb, - filePath, - lineNumber); - } - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Action handler, - [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", - [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) - { - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( - endpoints, - pattern, - handler, - GetVerb, - filePath, - lineNumber); - } - } } @@ -149,507 +69,576 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { + private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 44, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_44( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) { - [(@"TestMapActions.cs", 44)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 44)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 44)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Action)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); - }, - options.EndpointBuilder, - handler.Method); - } + } + handler(ic.GetArgument(0)!); + return ValueTask.FromResult(Results.Empty); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - Task RequestHandler(HttpContext httpContext) + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + // Endpoint Parameter: Value (Type = int, IsOptional = True, IsParsable = True, IsArray = False, Source = Route) + if (options?.RouteParameterNames?.Contains("Value", StringComparer.OrdinalIgnoreCase) != true) { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - // Endpoint Parameter: Value (Type = int, IsOptional = True, IsParsable = True, IsArray = False, Source = Route) - if (options?.RouteParameterNames?.Contains("Value", StringComparer.OrdinalIgnoreCase) != true) - { - throw new InvalidOperationException($"'Value' is not a route parameter."); - } - var Value_raw = (string?)httpContext.Request.RouteValues["Value"]; - var Value_temp = (string?)Value_raw; - global::System.Int32 Value_parsed_temp = default; - if (GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_temp_parsed_non_nullable)) - { - Value_parsed_temp = Value_temp_parsed_non_nullable; - } - else if (string.IsNullOrEmpty(Value_temp)) - { - Value_parsed_temp = 42; - } - else - { - wasParamCheckFailure = true; - } - int Value_local = Value_parsed_temp!; + throw new InvalidOperationException($"'Value' is not a route parameter."); + } + var Value_raw = (string?)httpContext.Request.RouteValues["Value"]; + var Value_temp = (string?)Value_raw; + global::System.Int32 Value_parsed_temp = default; + if (GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_temp_parsed_non_nullable)) + { + Value_parsed_temp = Value_temp_parsed_non_nullable; + } + else if (string.IsNullOrEmpty(Value_temp)) + { + Value_parsed_temp = 42; + } + else + { + wasParamCheckFailure = true; + } + int Value_local = Value_parsed_temp!; - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue(HttpContext_local, Value_local); + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue(HttpContext_local, Value_local); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - handler(args_local); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; return Task.CompletedTask; } + handler(args_local); + return Task.CompletedTask; + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + // Endpoint Parameter: Value (Type = int, IsOptional = True, IsParsable = True, IsArray = False, Source = Route) + if (options?.RouteParameterNames?.Contains("Value", StringComparer.OrdinalIgnoreCase) != true) { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - // Endpoint Parameter: Value (Type = int, IsOptional = True, IsParsable = True, IsArray = False, Source = Route) - if (options?.RouteParameterNames?.Contains("Value", StringComparer.OrdinalIgnoreCase) != true) - { - throw new InvalidOperationException($"'Value' is not a route parameter."); - } - var Value_raw = (string?)httpContext.Request.RouteValues["Value"]; - var Value_temp = (string?)Value_raw; - global::System.Int32 Value_parsed_temp = default; - if (GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_temp_parsed_non_nullable)) - { - Value_parsed_temp = Value_temp_parsed_non_nullable; - } - else if (string.IsNullOrEmpty(Value_temp)) - { - Value_parsed_temp = 42; - } - else - { - wasParamCheckFailure = true; - } - int Value_local = Value_parsed_temp!; + throw new InvalidOperationException($"'Value' is not a route parameter."); + } + var Value_raw = (string?)httpContext.Request.RouteValues["Value"]; + var Value_temp = (string?)Value_raw; + global::System.Int32 Value_parsed_temp = default; + if (GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_temp_parsed_non_nullable)) + { + Value_parsed_temp = Value_temp_parsed_non_nullable; + } + else if (string.IsNullOrEmpty(Value_temp)) + { + Value_parsed_temp = 42; + } + else + { + wasParamCheckFailure = true; + } + int Value_local = Value_parsed_temp!; - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue(HttpContext_local, Value_local); + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue(HttpContext_local, Value_local); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 45)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 45)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 45, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_45( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 45)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Action)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var Value_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("Value", options.RouteParameterNames); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); - }, - options.EndpointBuilder, - handler.Method); - } + } + handler(ic.GetArgument(0)!); + return ValueTask.FromResult(Results.Empty); + }, + options.EndpointBuilder, + handler.Method); + } - Task RequestHandler(HttpContext httpContext) + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var Value_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("Value", options?.RouteParameterNames); + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + // Endpoint Parameter: Value (Type = int, IsOptional = False, IsParsable = True, IsArray = False, Source = RouteOrQuery) + var Value_raw = Value_RouteOrQueryResolver(httpContext); + if (Value_raw is StringValues { Count: 0 }) { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - // Endpoint Parameter: Value (Type = int, IsOptional = False, IsParsable = True, IsArray = False, Source = RouteOrQuery) - var Value_raw = Value_RouteOrQueryResolver(httpContext); - if (Value_raw is StringValues { Count: 0 }) + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("int", "Value", "route or query string"); + } + var Value_temp = (string?)Value_raw; + if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_parsed_temp)) + { + if (!string.IsNullOrEmpty(Value_temp)) { + logOrThrowExceptionHelper.ParameterBindingFailed("int", "Value", Value_temp); wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("int", "Value", "route or query string"); - } - var Value_temp = (string?)Value_raw; - if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_parsed_temp)) - { - if (!string.IsNullOrEmpty(Value_temp)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("int", "Value", Value_temp); - wasParamCheckFailure = true; - } } - int Value_local = Value_parsed_temp!; + } + int Value_local = Value_parsed_temp!; - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct { HttpContext = HttpContext_local, Value = Value_local }; + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct { HttpContext = HttpContext_local, Value = Value_local }; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - handler(args_local); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; return Task.CompletedTask; } + handler(args_local); + return Task.CompletedTask; + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + // Endpoint Parameter: Value (Type = int, IsOptional = False, IsParsable = True, IsArray = False, Source = RouteOrQuery) + var Value_raw = Value_RouteOrQueryResolver(httpContext); + if (Value_raw is StringValues { Count: 0 }) + { + wasParamCheckFailure = true; + logOrThrowExceptionHelper.RequiredParameterNotProvided("int", "Value", "route or query string"); + } + var Value_temp = (string?)Value_raw; + if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_parsed_temp)) { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - // Endpoint Parameter: Value (Type = int, IsOptional = False, IsParsable = True, IsArray = False, Source = RouteOrQuery) - var Value_raw = Value_RouteOrQueryResolver(httpContext); - if (Value_raw is StringValues { Count: 0 }) + if (!string.IsNullOrEmpty(Value_temp)) { + logOrThrowExceptionHelper.ParameterBindingFailed("int", "Value", Value_temp); wasParamCheckFailure = true; - logOrThrowExceptionHelper.RequiredParameterNotProvided("int", "Value", "route or query string"); } - var Value_temp = (string?)Value_raw; - if (!GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_parsed_temp)) - { - if (!string.IsNullOrEmpty(Value_temp)) - { - logOrThrowExceptionHelper.ParameterBindingFailed("int", "Value", Value_temp); - wasParamCheckFailure = true; - } - } - int Value_local = Value_parsed_temp!; + } + int Value_local = Value_parsed_temp!; - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct { HttpContext = HttpContext_local, Value = Value_local }; + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct { HttpContext = HttpContext_local, Value = Value_local }; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 46)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 46)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 46, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_46( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 46)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Action)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); - }, - options.EndpointBuilder, - handler.Method); - } + } + handler(ic.GetArgument(0)!); + return ValueTask.FromResult(Results.Empty); + }, + options.EndpointBuilder, + handler.Method); + } - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - var User_local = httpContext.User; - var Request_local = httpContext.Request; - var Response_local = httpContext.Response; + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext(HttpContext_local, User_local, Request_local, Response_local); + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + var User_local = httpContext.User; + var Request_local = httpContext.Request; + var Response_local = httpContext.Response; - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - handler(args_local); + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext(HttpContext_local, User_local, Request_local, Response_local); + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; return Task.CompletedTask; } + handler(args_local); + return Task.CompletedTask; + } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - var User_local = httpContext.User; - var Request_local = httpContext.Request; - var Response_local = httpContext.Response; + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + var User_local = httpContext.User; + var Request_local = httpContext.Request; + var Response_local = httpContext.Response; - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext(HttpContext_local, User_local, Request_local, Response_local); + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext(HttpContext_local, User_local, Request_local, Response_local); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 47)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 47)); - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.JsonContentType)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 47, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_47( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 47)); + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: null, statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.PlaintextContentType)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Func)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serviceProviderIsService = serviceProvider?.GetService(); - var Todo_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "TodoStruct", "Todo", serviceProviderIsService); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); - }, - options.EndpointBuilder, - handler.Method); - } + return ValueTask.FromResult(Results.Empty); + } + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + }, + options.EndpointBuilder, + handler.Method); + } + + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serviceProviderIsService = serviceProvider?.GetService(); + var Todo_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "TodoStruct", "Todo", serviceProviderIsService); - async Task RequestHandler(HttpContext httpContext) + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + // Endpoint Parameter: Todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.TodoStruct, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var Todo_resolveJsonBodyOrServiceResult = await Todo_JsonBodyOrServiceResolver(httpContext, false); + var Todo_local = Todo_resolveJsonBodyOrServiceResult.Item2; + if (!Todo_resolveJsonBodyOrServiceResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - // Endpoint Parameter: Todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.TodoStruct, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var Todo_resolveJsonBodyOrServiceResult = await Todo_JsonBodyOrServiceResolver(httpContext, false); - var Todo_local = Todo_resolveJsonBodyOrServiceResult.Item2; - if (!Todo_resolveJsonBodyOrServiceResult.Item1) - { - return; - } + return; + } - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody(HttpContext_local, Todo_local); + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody(HttpContext_local, Todo_local); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - var result = handler(args_local); - if (result is string) - { - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; - } - else - { - httpContext.Response.ContentType ??= "application/json; charset=utf-8"; - } - await httpContext.Response.WriteAsync(result); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; } + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + var result = handler(args_local); + await httpContext.Response.WriteAsync(result); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + // Endpoint Parameter: Todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.TodoStruct, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var Todo_resolveJsonBodyOrServiceResult = await Todo_JsonBodyOrServiceResolver(httpContext, false); + var Todo_local = Todo_resolveJsonBodyOrServiceResult.Item2; + if (!Todo_resolveJsonBodyOrServiceResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - // Endpoint Parameter: Todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.TodoStruct, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var Todo_resolveJsonBodyOrServiceResult = await Todo_JsonBodyOrServiceResolver(httpContext, false); - var Todo_local = Todo_resolveJsonBodyOrServiceResult.Item2; - if (!Todo_resolveJsonBodyOrServiceResult.Item1) - { - return; - } + return; + } - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody(HttpContext_local, Todo_local); + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody(HttpContext_local, Todo_local); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - [(@"TestMapActions.cs", 48)] = ( - (methodInfo, options) => - { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 48)); - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.JsonContentType)); - var parameterInfos = methodInfo.GetParameters(); - var Value_ParameterInfo = new PropertyAsParameterInfo(false, typeof(Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType)!.GetProperty("Value")!, typeof(Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType).GetConstructor(new[] { typeof(Microsoft.AspNetCore.Http.HttpContext), typeof(Microsoft.AspNetCore.Http.Generators.Tests.AddsCustomParameterMetadataAsProperty) })?.GetParameters()[1]); - PopulateMetadataForParameter(Value_ParameterInfo, options.EndpointBuilder); - PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + PostVerb, + populateMetadata, + createRequestDelegate); + } + +[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 48, 5)] + internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_48( + this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, + [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, + global::System.Delegate handler) + { + MetadataPopulator populateMetadata = (methodInfo, options) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 48)); + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.JsonContentType)); + var parameterInfos = methodInfo.GetParameters(); + var Value_ParameterInfo = new PropertyAsParameterInfo(false, typeof(Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType)!.GetProperty("Value")!, typeof(Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType).GetConstructor(new[] { typeof(Microsoft.AspNetCore.Http.HttpContext), typeof(Microsoft.AspNetCore.Http.Generators.Tests.AddsCustomParameterMetadataAsProperty) })?.GetParameters()[1]); + PopulateMetadataForParameter(Value_ParameterInfo, options.EndpointBuilder); + PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }; + RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => + { + Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); + Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); + Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); + Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); + var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType arg0) => throw null!); + EndpointFilterDelegate? filteredInvocation = null; + if (options.EndpointBuilder.FilterFactories.Count > 0) { - Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); - Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); - Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); - Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = (System.Action)del; - EndpointFilterDelegate? filteredInvocation = null; - var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; - var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); - var serviceProviderIsService = serviceProvider?.GetService(); - var Value_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "AddsCustomParameterMetadataAsProperty", "Value", serviceProviderIsService); - - if (options.EndpointBuilder.FilterFactories.Count > 0) + filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => { - filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic => + if (ic.HttpContext.Response.StatusCode == 400) { - if (ic.HttpContext.Response.StatusCode == 400) - { - return ValueTask.FromResult(Results.Empty); - } - handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); - }, - options.EndpointBuilder, - handler.Method); - } + } + handler(ic.GetArgument(0)!); + return ValueTask.FromResult(Results.Empty); + }, + options.EndpointBuilder, + handler.Method); + } - async Task RequestHandler(HttpContext httpContext) + var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; + var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); + var serviceProviderIsService = serviceProvider?.GetService(); + var Value_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "AddsCustomParameterMetadataAsProperty", "Value", serviceProviderIsService); + + async Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + // Endpoint Parameter: Value (Type = Microsoft.AspNetCore.Http.Generators.Tests.AddsCustomParameterMetadataAsProperty, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var Value_resolveJsonBodyOrServiceResult = await Value_JsonBodyOrServiceResolver(httpContext, false); + var Value_local = Value_resolveJsonBodyOrServiceResult.Item2; + if (!Value_resolveJsonBodyOrServiceResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - // Endpoint Parameter: Value (Type = Microsoft.AspNetCore.Http.Generators.Tests.AddsCustomParameterMetadataAsProperty, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var Value_resolveJsonBodyOrServiceResult = await Value_JsonBodyOrServiceResolver(httpContext, false); - var Value_local = Value_resolveJsonBodyOrServiceResult.Item2; - if (!Value_resolveJsonBodyOrServiceResult.Item1) - { - return; - } + return; + } - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType(HttpContext_local, Value_local); + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType(HttpContext_local, Value_local); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return; - } - handler(args_local); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return; } + handler(args_local); + } - async Task RequestHandlerFiltered(HttpContext httpContext) + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) + var HttpContext_local = httpContext; + // Endpoint Parameter: Value (Type = Microsoft.AspNetCore.Http.Generators.Tests.AddsCustomParameterMetadataAsProperty, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) + var Value_resolveJsonBodyOrServiceResult = await Value_JsonBodyOrServiceResolver(httpContext, false); + var Value_local = Value_resolveJsonBodyOrServiceResult.Item2; + if (!Value_resolveJsonBodyOrServiceResult.Item1) { - var wasParamCheckFailure = false; - // Endpoint Parameter: args (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType, IsOptional = False, IsParsable = False, IsArray = False, Source = AsParameters) - var HttpContext_local = httpContext; - // Endpoint Parameter: Value (Type = Microsoft.AspNetCore.Http.Generators.Tests.AddsCustomParameterMetadataAsProperty, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBodyOrService) - var Value_resolveJsonBodyOrServiceResult = await Value_JsonBodyOrServiceResolver(httpContext, false); - var Value_local = Value_resolveJsonBodyOrServiceResult.Item2; - if (!Value_resolveJsonBodyOrServiceResult.Item1) - { - return; - } + return; + } - var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType(HttpContext_local, Value_local); + var args_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType(HttpContext_local, Value_local); - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; } + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; + var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; + return new RequestDelegateResult(targetDelegate, metadata); + }; + return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + endpoints, + pattern, + handler, + GetVerb, + populateMetadata, + createRequestDelegate); + } - RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered; - var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; - return new RequestDelegateResult(targetDelegate, metadata); - }), - }; internal static RouteHandlerBuilder MapCore( this IEndpointRouteBuilder routes, string pattern, Delegate handler, IEnumerable? httpMethods, - string filePath, - int lineNumber) + MetadataPopulator populateMetadata, + RequestDelegateFactoryFunc createRequestDelegate) { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); } + private static T Cast(Delegate d, T _) where T : Delegate + { + return (T)d; + } + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) { var routeHandlerFilters = builder.FilterFactories; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/CompileTimeCreationTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/CompileTimeCreationTests.cs index 73765896ab98..21f0bc9eb83a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/CompileTimeCreationTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/CompileTimeCreationTests.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.CodeAnalysis; using Microsoft.AspNetCore.Http.RequestDelegateGenerator; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Http.Generators.Tests; @@ -37,4 +38,28 @@ public async Task MapAction_ExplicitRouteParamWithInvalidName_SimpleReturn() var exception = await Assert.ThrowsAsync(() => endpoint.RequestDelegate(httpContext)); Assert.Equal("'invalidName' is not a route parameter.", exception.Message); } + + [Fact] + public async Task MapAction_SupportsParametersWithDifferingNullability() + { + var source = """ +app.MapGet("/hello", (string name) => $"Hello {name}!"); +app.MapGet("/hello2", (string? name) => $"Hello {name ?? string.Empty}!"); +"""; + var (result, compilation) = await RunGeneratorAsync(source); + var endpoints = GetEndpointsFromCompilation(compilation); + + foreach (var endpoint in endpoints) + { + var httpContext = CreateHttpContext(); + httpContext.Request.Query = new QueryCollection(new Dictionary() + { + { + "name", "world" + } + }); + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "Hello world!"); + } + } } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs index 443768397f0b..8a90145507ae 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs @@ -35,8 +35,6 @@ public abstract class RequestDelegateCreationTestBase : LoggedTest internal async Task<(GeneratorRunResult?, Compilation)> RunGeneratorAsync(string sources, params string[] updatedSources) { - var source = GetMapActionString(sources); - var project = _baseProject.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project; // Create a Roslyn compilation for the syntax tree. var compilation = await CreateCompilationAsync(sources); @@ -55,12 +53,13 @@ public abstract class RequestDelegateCreationTestBase : LoggedTest { generator }, - driverOptions: new GeneratorDriverOptions(IncrementalGeneratorOutputKind.None, trackIncrementalGeneratorSteps: true)); + driverOptions: new GeneratorDriverOptions(IncrementalGeneratorOutputKind.None, trackIncrementalGeneratorSteps: true), + parseOptions: new CSharpParseOptions(LanguageVersion.Preview)); driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var updatedCompilation, out var _); foreach (var updatedSource in updatedSources) { - var syntaxTree = CSharpSyntaxTree.ParseText(GetMapActionString(updatedSource), path: $"TestMapActions.cs"); + var syntaxTree = CSharpSyntaxTree.ParseText(GetMapActionString(updatedSource), path: $"TestMapActions.cs", options: new CSharpParseOptions(LanguageVersion.Preview)); compilation = compilation .ReplaceSyntaxTree(compilation.SyntaxTrees.First(), syntaxTree); driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out updatedCompilation, @@ -73,24 +72,24 @@ public abstract class RequestDelegateCreationTestBase : LoggedTest return (Assert.Single(runResult.Results), updatedCompilation); } - internal static RequestDelegateGenerator.StaticRouteHandlerModel.Endpoint GetStaticEndpoint(GeneratorRunResult result, string stepName) => + internal static RequestDelegateGenerator.StaticRouteHandler.Model.Endpoint GetStaticEndpoint(GeneratorRunResult result, string stepName) => Assert.Single(GetStaticEndpoints(result, stepName)); - internal static RequestDelegateGenerator.StaticRouteHandlerModel.Endpoint[] GetStaticEndpoints(GeneratorRunResult result, string stepName) + internal static RequestDelegateGenerator.StaticRouteHandler.Model.Endpoint[] GetStaticEndpoints(GeneratorRunResult result, string stepName) { // We only invoke the generator once in our test scenarios if (result.TrackedSteps.TryGetValue(stepName, out var staticEndpointSteps)) { return staticEndpointSteps .SelectMany(step => step.Outputs) - .Select(output => Assert.IsType(output.Value)) + .Select(output => Assert.IsType(output.Value)) .ToArray(); } - return Array.Empty(); + return Array.Empty(); } - internal static void VerifyStaticEndpointModel(GeneratorRunResult? result, Action runAssertions) + internal static void VerifyStaticEndpointModel(GeneratorRunResult? result, Action runAssertions) { if (result.HasValue) { @@ -98,7 +97,7 @@ internal static void VerifyStaticEndpointModel(GeneratorRunResult? result, Actio } } - internal static void VerifyStaticEndpointModels(GeneratorRunResult? result, Action runAssertions) + internal static void VerifyStaticEndpointModels(GeneratorRunResult? result, Action runAssertions) { if (result.HasValue) { @@ -134,7 +133,7 @@ internal Endpoint[] GetEndpointsFromCompilation(Compilation compilation, bool? e var sourceText = SourceText.From(buffer, buffer.Length, encoding, canBeEmbedded: true); var syntaxRootNode = (CSharpSyntaxNode)syntaxTree.GetRoot(); - var newSyntaxTree = CSharpSyntaxTree.Create(syntaxRootNode, options: null, encoding: encoding, path: syntaxTree.FilePath); + var newSyntaxTree = CSharpSyntaxTree.Create(syntaxRootNode, options: new CSharpParseOptions(LanguageVersion.Preview), encoding: encoding, path: syntaxTree.FilePath); compilation = compilation.ReplaceSyntaxTree(syntaxTree, newSyntaxTree); @@ -301,7 +300,7 @@ private static Project CreateProject() .AddProject(projectName, projectName, LanguageNames.CSharp) .WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) .WithNullableContextOptions(NullableContextOptions.Enable)) - .WithParseOptions(new CSharpParseOptions(LanguageVersion.CSharp11)); + .WithParseOptions(new CSharpParseOptions(LanguageVersion.Preview)); // Add in required metadata references var resolver = new AppLocalResolver(); @@ -347,7 +346,7 @@ internal async Task VerifyAgainstBaselineUsingFile(Compilation compilation, [Cal .Replace(RequestDelegateGeneratorSources.GeneratedCodeAttribute, "%GENERATEDCODEATTRIBUTE%") + Environment.NewLine; await File.WriteAllTextAsync(baselineFilePath, newSource); - Assert.Fail("RegenerateBaselines=true. Do not merge PRs with this set."); + // Assert.Fail("RegenerateBaselines=true. Do not merge PRs with this set."); } var baseline = await File.ReadAllTextAsync(baselineFilePath); diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Arrays.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Arrays.cs index d7bf9bdef497..4c4fcb8b2e40 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Arrays.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Arrays.cs @@ -9,7 +9,7 @@ using System.Text.Encodings.Web; using System.Text.Json; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.Extensions.Primitives; using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.BindAsync.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.BindAsync.cs index d941bd4e52bb..a0ce3321b8c1 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.BindAsync.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.BindAsync.cs @@ -12,7 +12,7 @@ using System.Text.Json; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Json; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Metadata.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Metadata.cs index dae0f0581d0e..432b5bfb2855 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Metadata.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.Metadata.cs @@ -10,7 +10,7 @@ using System.Text.Encodings.Web; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Metadata; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.QueryParameters.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.QueryParameters.cs index 8ad843fab793..a7f3e659cc7e 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.QueryParameters.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.QueryParameters.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Text; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.SpecialTypes.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.SpecialTypes.cs index f74c5e367c1a..edfb022175a8 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.SpecialTypes.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.SpecialTypes.cs @@ -12,7 +12,7 @@ using System.Text.Encodings.Web; using System.Text.Json; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Primitives; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.TryParse.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.TryParse.cs index 9213f23b869c..90dc22a01aa1 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.TryParse.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.TryParse.cs @@ -6,7 +6,7 @@ using System.Reflection; using System.Reflection.Metadata; using System.Text.Encodings.Web; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Http.Generators.Tests; diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.cs index 8823f162b56b..261982b24fc1 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.cs @@ -1,17 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Globalization; -using System.Net; -using System.Net.Sockets; -using System.Numerics; -using System.Reflection; -using System.Reflection.Metadata; -using System.Text; -using System.Text.Encodings.Web; -using System.Text.Json; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel; +using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Primitives; diff --git a/src/Shared/RoslynUtils/CodeWriter.cs b/src/Shared/RoslynUtils/CodeWriter.cs index 079aad0085dd..eff1aa12a9c1 100644 --- a/src/Shared/RoslynUtils/CodeWriter.cs +++ b/src/Shared/RoslynUtils/CodeWriter.cs @@ -30,6 +30,12 @@ public void EndBlockWithComma() this.WriteLine("},"); } + public void EndBlockWithSemicolon() + { + this.Indent--; + this.WriteLine("};"); + } + // The IndentedTextWriter adds the indentation // _after_ writing the first line of text. This // method can be used ot initialize indentation From f673431cd4a89b5e4e7e728bc483c8669c5b47f9 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Sat, 3 Jun 2023 17:41:49 -0700 Subject: [PATCH 2/7] Address feedback from peer review --- .../gen/RequestDelegateGenerator.cs | 16 +- .../gen/RequestDelegateGeneratorSources.cs | 11 +- .../Emitters/EmitterConstants.cs | 4 +- .../gen/StaticRouteHandler/Model/Endpoint.cs | 3 +- ...MapAction_BindAsync_Snapshot.generated.txt | 373 +++++++++--------- ...Param_ComplexReturn_Snapshot.generated.txt | 65 +-- ...Header_ComplexTypeArrayParam.generated.txt | 39 +- ...der_NullableStringArrayParam.generated.txt | 35 +- ...licitHeader_StringArrayParam.generated.txt | 35 +- ...tQuery_ComplexTypeArrayParam.generated.txt | 39 +- ...ery_NullableStringArrayParam.generated.txt | 35 +- ...plicitQuery_StringArrayParam.generated.txt | 35 +- ...eParam_SimpleReturn_Snapshot.generated.txt | 67 ++-- ...Source_SimpleReturn_Snapshot.generated.txt | 103 ++--- ...tQuery_ComplexTypeArrayParam.generated.txt | 39 +- ...ery_NullableStringArrayParam.generated.txt | 43 +- ...gArrayParam_EmptyQueryValues.generated.txt | 43 +- ...ngArrayParam_QueryNotPresent.generated.txt | 43 +- ...plicitQuery_StringArrayParam.generated.txt | 43 +- ...ce_HandlesBothJsonAndService.generated.txt | 39 +- ...pecialTypeParam_StringReturn.generated.txt | 31 +- ...ipleStringParam_StringReturn.generated.txt | 31 +- ...aram_StringReturn_WithFilter.generated.txt | 27 +- ...n_ReturnsString_Has_Metadata.generated.txt | 27 +- ...ion_ReturnsTodo_Has_Metadata.generated.txt | 31 +- ...onProblemResult_Has_Metadata.generated.txt | 29 +- ..._ReturnsVoid_Has_No_Metadata.generated.txt | 25 +- ...omplexTypeParam_StringReturn.generated.txt | 31 +- ...SingleEnumParam_StringReturn.generated.txt | 31 +- ...ngValueProvided_StringReturn.generated.txt | 31 +- ...MetadataEmitter_Has_Metadata.generated.txt | 39 +- ...AndBody_ShouldUseQueryString.generated.txt | 41 +- ...AndBody_ShouldUseQueryString.generated.txt | 41 +- ...String_AndBody_ShouldUseBody.generated.txt | 41 +- ...String_AndBody_ShouldUseBody.generated.txt | 41 +- ...String_AndBody_ShouldUseBody.generated.txt | 39 +- ...hArrayQueryString_ShouldFail.generated.txt | 43 +- ...pAction_NoParam_StringReturn.generated.txt | 69 ++-- ...tion_WithParams_StringReturn.generated.txt | 67 ++-- ...ateValidateGeneratedFormCode.generated.txt | 31 +- .../VerifyAsParametersBaseline.generated.txt | 115 +++--- .../RequestDelegateCreationTestBase.cs | 2 +- 42 files changed, 1005 insertions(+), 968 deletions(-) diff --git a/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs b/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs index b8dc95ed6579..781b00a7c681 100644 --- a/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs +++ b/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs @@ -60,21 +60,21 @@ public void Initialize(IncrementalGeneratorInitializationContext context) { using var stringWriter = new StringWriter(CultureInfo.InvariantCulture); using var codeWriter = new CodeWriter(stringWriter, baseIndent: 2); - codeWriter.WriteLine($$"""[global::System.Runtime.CompilerServices.InterceptsLocation(@"{{endpoint!.Location.File}}", {{endpoint.Location.LineNumber}}, {{endpoint.Location.CharaceterNumber + 1}})]"""); - codeWriter.WriteLine($"internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder {endpoint!.HttpMethod}_{endpoint.Location.LineNumber}("); + codeWriter.WriteLine($$"""[InterceptsLocation(@"{{endpoint.Location.File}}", {{endpoint.Location.LineNumber}}, {{endpoint.Location.CharacterNumber + 1}})]"""); + codeWriter.WriteLine($"internal static RouteHandlerBuilder {endpoint.HttpMethod}_{endpoint.Location.LineNumber}("); codeWriter.Indent++; - codeWriter.WriteLine("this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints,"); + codeWriter.WriteLine("this IEndpointRouteBuilder endpoints,"); // MapFallback overloads that only take a delegate do not need a pattern argument if (endpoint.HttpMethod != "MapFallback" || endpoint.Operation.Arguments.Length != 2) { - codeWriter.WriteLine(@"[global::System.Diagnostics.CodeAnalysis.StringSyntax(""Route"")] string pattern,"); + codeWriter.WriteLine(@"[StringSyntax(""Route"")] string pattern,"); } // MapMethods overloads define an additional `httpMethods` parameter if (endpoint.HttpMethod == "MapMethods") { - codeWriter.WriteLine("global::System.Collections.Generic.IEnumerable httpMethods,"); + codeWriter.WriteLine("IEnumerable httpMethods,"); } - codeWriter.WriteLine($"global::System.Delegate handler)"); + codeWriter.WriteLine("Delegate handler)"); codeWriter.Indent--; codeWriter.StartBlock(); codeWriter.WriteLine("MetadataPopulator populateMetadata = (methodInfo, options) =>"); @@ -135,7 +135,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) codeWriter.WriteLine("return new RequestDelegateResult(targetDelegate, metadata);"); codeWriter.EndBlockWithSemicolon(); - codeWriter.WriteLine("return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore("); + codeWriter.WriteLine("return GeneratedRouteBuilderExtensionsCore.MapCore("); codeWriter.Indent++; codeWriter.WriteLine("endpoints,"); // For `MapFallback` overloads that only take a delegate, provide the assumed default @@ -149,7 +149,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) codeWriter.WriteLine($"{SymbolDisplay.FormatLiteral("{*path:nonfile}", true)},"); } codeWriter.WriteLine("handler,"); - codeWriter.WriteLine($"{endpoint!.EmitVerb()},"); + codeWriter.WriteLine($"{endpoint.EmitVerb()},"); codeWriter.WriteLine("populateMetadata,"); codeWriter.WriteLine($"createRequestDelegate);"); codeWriter.Indent--; diff --git a/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs b/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs index cbe395f478cb..43cc459762dd 100644 --- a/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs +++ b/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs @@ -542,6 +542,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -564,11 +565,11 @@ namespace Microsoft.AspNetCore.Http.Generated {{GeneratedCodeAttribute}} file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; {{endpoints}} diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterConstants.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterConstants.cs index e6ee10bad40a..88fe875804dc 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterConstants.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterConstants.cs @@ -7,13 +7,13 @@ namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler. internal static class EmitterConstants { public static SymbolDisplayFormat DisplayFormat => new SymbolDisplayFormat( - globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, + globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted, genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier); public static SymbolDisplayFormat DisplayFormatWithoutNullability => new SymbolDisplayFormat( - globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, + globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted, genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces); } diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs index 7d8ead63e021..da10a2cec3e6 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs @@ -90,13 +90,12 @@ public Endpoint(IInvocationOperation operation, WellKnownTypes wellKnownTypes, S public string HttpMethod { get; } public bool IsAwaitable { get; set; } public bool NeedsParameterArray { get; } - public string? RoutePattern { get; } public EmitterContext EmitterContext { get; } public EndpointResponse? Response { get; } public EndpointParameter[] Parameters { get; } = Array.Empty(); public List Diagnostics { get; } = new List(); - public (string File, int LineNumber, int CharaceterNumber) Location { get; } + public (string File, int LineNumber, int CharacterNumber) Location { get; } public IInvocationOperation Operation { get; } public override bool Equals(object o) => diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt index f9dec7d0b84d..01c4f0b22cd9 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -163,7 +164,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -171,7 +172,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -180,11 +181,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static RouteHandlerBuilder MapGet_26( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -200,7 +201,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncRecord? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -210,7 +211,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -246,7 +247,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -254,7 +255,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -263,11 +264,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static RouteHandlerBuilder MapGet_27( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -283,7 +284,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -293,7 +294,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -351,7 +352,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -359,7 +360,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -368,11 +369,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 28, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_28( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 28, 5)] + internal static RouteHandlerBuilder MapGet_28( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -388,7 +389,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncStruct? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -398,7 +399,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -434,7 +435,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -442,7 +443,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -451,11 +452,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 29, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_29( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 29, 5)] + internal static RouteHandlerBuilder MapGet_29( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -471,7 +472,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -481,7 +482,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -539,7 +540,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -547,7 +548,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -556,11 +557,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 30, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_30( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 30, 5)] + internal static RouteHandlerBuilder MapGet_30( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -576,7 +577,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.MyNullableBindAsyncStruct? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -586,7 +587,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -622,7 +623,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -630,7 +631,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -639,11 +640,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 31, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_31( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 31, 5)] + internal static RouteHandlerBuilder MapGet_31( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -659,7 +660,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -669,7 +670,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -727,7 +728,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -735,7 +736,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -744,11 +745,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 32, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_32( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 32, 5)] + internal static RouteHandlerBuilder MapGet_32( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -764,7 +765,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.MyBothBindAsyncStruct? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -774,7 +775,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -810,7 +811,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -818,7 +819,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -827,11 +828,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 33, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_33( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 33, 5)] + internal static RouteHandlerBuilder MapGet_33( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -847,7 +848,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -857,7 +858,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -914,7 +915,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -922,7 +923,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -931,11 +932,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 34, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_34( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 34, 5)] + internal static RouteHandlerBuilder MapGet_34( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -951,7 +952,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncRecord? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -961,7 +962,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -996,7 +997,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1004,7 +1005,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1013,11 +1014,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 35, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_35( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 35, 5)] + internal static RouteHandlerBuilder MapGet_35( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1033,7 +1034,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1043,7 +1044,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -1100,7 +1101,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1108,7 +1109,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1117,11 +1118,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 36, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_36( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 36, 5)] + internal static RouteHandlerBuilder MapGet_36( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1137,7 +1138,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.MySimpleBindAsyncStruct? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1147,7 +1148,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -1182,7 +1183,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1190,7 +1191,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1199,11 +1200,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 37, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_37( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 37, 5)] + internal static RouteHandlerBuilder MapGet_37( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1219,7 +1220,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1229,7 +1230,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -1287,7 +1288,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1295,7 +1296,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1304,11 +1305,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 38, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_38( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 38, 5)] + internal static RouteHandlerBuilder MapGet_38( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1324,7 +1325,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromImplicitStaticAbstractInterface? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1334,7 +1335,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -1370,7 +1371,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1378,7 +1379,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1387,11 +1388,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 39, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_39( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 39, 5)] + internal static RouteHandlerBuilder MapGet_39( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1407,7 +1408,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1417,7 +1418,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -1474,7 +1475,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1482,7 +1483,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1491,11 +1492,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 40, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_40( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 40, 5)] + internal static RouteHandlerBuilder MapGet_40( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1511,7 +1512,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.InheritBindAsync? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1521,7 +1522,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -1556,7 +1557,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1564,7 +1565,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1573,11 +1574,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 41, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_41( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 41, 5)] + internal static RouteHandlerBuilder MapGet_41( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1593,7 +1594,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1603,7 +1604,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -1661,7 +1662,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1669,7 +1670,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1678,11 +1679,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 42, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_42( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 42, 5)] + internal static RouteHandlerBuilder MapGet_42( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1698,7 +1699,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.BindAsyncFromExplicitStaticAbstractInterface? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1708,7 +1709,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -1744,7 +1745,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1752,7 +1753,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1761,11 +1762,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 43, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_43( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 43, 5)] + internal static RouteHandlerBuilder MapGet_43( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1781,7 +1782,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1791,7 +1792,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -1848,7 +1849,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1856,7 +1857,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -1865,11 +1866,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 44, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_44( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 44, 5)] + internal static RouteHandlerBuilder MapGet_44( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -1885,7 +1886,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord? arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.MyBindAsyncFromInterfaceRecord? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -1895,7 +1896,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -1930,7 +1931,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, myBindAsyncParam_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -1938,7 +1939,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt index 35713d096149..e45aab4bddee 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,25 +70,25 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapPost_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), isOptional: false, contentTypes: GeneratedMetadataConstants.JsonContentType)); - PopulateMetadataForEndpoint>(methodInfo, options.EndpointBuilder); + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof(Microsoft.AspNetCore.Http.Generators.Tests.Todo), isOptional: false, contentTypes: GeneratedMetadataConstants.JsonContentType)); + PopulateMetadataForEndpoint>(methodInfo, options.EndpointBuilder); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::Microsoft.AspNetCore.Http.HttpResults.Ok (global::Microsoft.AspNetCore.Http.Generators.Tests.Todo arg0) => throw null!); + var handler = Cast(del, Microsoft.AspNetCore.Http.HttpResults.Ok (Microsoft.AspNetCore.Http.Generators.Tests.Todo arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBody) - var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "Todo", "todo"); + var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "Todo", "todo"); var todo_local = todo_resolveBodyResult.Item2; if (!todo_resolveBodyResult.Item1) { @@ -139,7 +140,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo, IsOptional = False, IsParsable = False, IsArray = False, Source = JsonBody) - var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "Todo", "todo"); + var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "Todo", "todo"); var todo_local = todo_resolveBodyResult.Item2; if (!todo_resolveBodyResult.Item1) { @@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local!)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local!)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -167,19 +168,19 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_27( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static RouteHandlerBuilder MapPost_27( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 27)); - options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), isOptional: true, contentTypes: GeneratedMetadataConstants.JsonContentType)); - PopulateMetadataForEndpoint>(methodInfo, options.EndpointBuilder); + options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(type: typeof(Microsoft.AspNetCore.Http.Generators.Tests.Todo), isOptional: true, contentTypes: GeneratedMetadataConstants.JsonContentType)); + PopulateMetadataForEndpoint>(methodInfo, options.EndpointBuilder); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -188,7 +189,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::Microsoft.AspNetCore.Http.HttpResults.Ok (global::Microsoft.AspNetCore.Http.Generators.Tests.Todo? arg0) => throw null!); + var handler = Cast(del, Microsoft.AspNetCore.Http.HttpResults.Ok (Microsoft.AspNetCore.Http.Generators.Tests.Todo? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -198,7 +199,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -211,7 +212,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo?, IsOptional = True, IsParsable = False, IsArray = False, Source = JsonBody) - var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, true, "Todo?", "todo"); + var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, true, "Todo?", "todo"); var todo_local = todo_resolveBodyResult.Item2; if (!todo_resolveBodyResult.Item1) { @@ -231,7 +232,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: todo (Type = Microsoft.AspNetCore.Http.Generators.Tests.Todo?, IsOptional = True, IsParsable = False, IsArray = False, Source = JsonBody) - var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, true, "Todo?", "todo"); + var todo_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, true, "Todo?", "todo"); var todo_local = todo_resolveBodyResult.Item2; if (!todo_resolveBodyResult.Item1) { @@ -242,7 +243,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -250,7 +251,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt index 4c27b89d771a..37680ead65f9 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,7 +115,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); Task RequestHandler(HttpContext httpContext) { @@ -122,7 +123,7 @@ namespace Microsoft.AspNetCore.Http.Generated // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Header) var p_raw = httpContext.Request.Headers["p"]; var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; for (var i = 0; i < p_temp.Length; i++) { var element = p_temp[i]; @@ -153,7 +154,7 @@ namespace Microsoft.AspNetCore.Http.Generated // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Header) var p_raw = httpContext.Request.Headers["p"]; var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; for (var i = 0; i < p_temp.Length; i++) { var element = p_temp[i]; @@ -172,7 +173,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -180,7 +181,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt index fe64fcb619c3..08796ffb7c93 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String?[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,7 +115,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); Task RequestHandler(HttpContext httpContext) { @@ -146,7 +147,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -154,7 +155,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt index 519ba8dde312..c78aa1f82302 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,7 +115,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); Task RequestHandler(HttpContext httpContext) { @@ -146,7 +147,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -154,7 +155,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt index d4f7df046ef0..5c1005e041b9 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,7 +115,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); Task RequestHandler(HttpContext httpContext) { @@ -122,7 +123,7 @@ namespace Microsoft.AspNetCore.Http.Generated // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Query) var p_raw = httpContext.Request.Query["p"]; var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; for (var i = 0; i < p_temp.Length; i++) { var element = p_temp[i]; @@ -153,7 +154,7 @@ namespace Microsoft.AspNetCore.Http.Generated // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = Query) var p_raw = httpContext.Request.Query["p"]; var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; for (var i = 0; i < p_temp.Length; i++) { var element = p_temp[i]; @@ -172,7 +173,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -180,7 +181,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt index ee2a579a92be..b56f670c5ce5 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String?[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -113,7 +114,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); Task RequestHandler(HttpContext httpContext) { @@ -145,7 +146,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -153,7 +154,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt index 3260e814c9c6..8322cd1fbaa6 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -113,7 +114,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); Task RequestHandler(HttpContext httpContext) { @@ -145,7 +146,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -153,7 +154,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt index 5b8e2bcd91fc..5d2b7e12e851 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.TestService arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.TestService arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, svc_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, svc_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -157,11 +158,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static RouteHandlerBuilder MapGet_26( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -177,7 +178,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.Collections.Generic.IEnumerable arg0) => throw null!); + var handler = Cast(del, System.String (System.Collections.Generic.IEnumerable arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -187,7 +188,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument>(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument>(0)!)); }, options.EndpointBuilder, handler.Method); @@ -222,7 +223,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create>(httpContext, svc_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create>(httpContext, svc_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -230,7 +231,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -239,11 +240,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static RouteHandlerBuilder MapGet_27( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -259,7 +260,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.TestService? arg0, global::System.Collections.Generic.IEnumerable arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.TestService? arg0, System.Collections.Generic.IEnumerable arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -269,7 +270,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument>(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument>(1)!)); }, options.EndpointBuilder, handler.Method); @@ -308,7 +309,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create>(httpContext, svc_local, svcs_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create>(httpContext, svc_local, svcs_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -316,7 +317,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt index ba04197d0e71..4caaffa6cbe0 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + var handler = Cast(del, System.String (System.String arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -154,7 +155,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, queryValue_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, queryValue_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -162,7 +163,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -171,11 +172,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static RouteHandlerBuilder MapGet_26( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -191,7 +192,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + var handler = Cast(del, System.String (System.String arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -201,7 +202,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -250,7 +251,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, headerValue_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, headerValue_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -258,7 +259,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -267,11 +268,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static RouteHandlerBuilder MapGet_27( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -287,7 +288,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + var handler = Cast(del, System.String (System.String arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -297,7 +298,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -354,7 +355,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, routeValue_local!)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, routeValue_local!)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -362,7 +363,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -371,11 +372,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 28, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_28( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 28, 5)] + internal static RouteHandlerBuilder MapGet_28( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -391,7 +392,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + var handler = Cast(del, System.String (System.String arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -401,7 +402,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -451,7 +452,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, value_local!)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, value_local!)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -459,7 +460,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -468,11 +469,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 29, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_29( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 29, 5)] + internal static RouteHandlerBuilder MapGet_29( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -488,7 +489,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String arg0) => throw null!); + var handler = Cast(del, System.String (System.String arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -498,7 +499,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -548,7 +549,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, value_local!)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, value_local!)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -556,7 +557,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt index 1b86253d53a4..a5f0367e2680 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -115,7 +116,7 @@ namespace Microsoft.AspNetCore.Http.Generated var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var p_RouteOrQueryResolver = GeneratedRouteBuilderExtensionsCore.ResolveFromRouteOrQuery("p", options?.RouteParameterNames); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); Task RequestHandler(HttpContext httpContext) { @@ -123,7 +124,7 @@ namespace Microsoft.AspNetCore.Http.Generated // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = RouteOrQuery) var p_raw = p_RouteOrQueryResolver(httpContext); var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; for (var i = 0; i < p_temp.Length; i++) { var element = p_temp[i]; @@ -154,7 +155,7 @@ namespace Microsoft.AspNetCore.Http.Generated // Endpoint Parameter: p (Type = Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[], IsOptional = False, IsParsable = True, IsArray = True, Source = RouteOrQuery) var p_raw = p_RouteOrQueryResolver(httpContext); var p_temp = p_raw.ToArray(); - global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new global::Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; + Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[] p_local = new Microsoft.AspNetCore.Http.Generators.Tests.ParsableTodo[p_temp.Length]; for (var i = 0; i < p_temp.Length; i++) { var element = p_temp[i]; @@ -173,7 +174,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local!)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local!)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -181,7 +182,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt index 9e26b5f9b207..89ba418bb23d 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String?[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,13 +115,13 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); async Task RequestHandler(HttpContext httpContext) { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; + System.String?[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -128,7 +129,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; + System.String?[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -178,7 +179,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt index 9e26b5f9b207..89ba418bb23d 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String?[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,13 +115,13 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); async Task RequestHandler(HttpContext httpContext) { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; + System.String?[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -128,7 +129,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; + System.String?[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -178,7 +179,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt index 9e26b5f9b207..89ba418bb23d 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String?[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String?[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,13 +115,13 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); async Task RequestHandler(HttpContext httpContext) { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; + System.String?[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -128,7 +129,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String?[] p_local = null!; + System.String?[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string?[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -178,7 +179,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt index 839821418f0d..b632986d8106 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,13 +115,13 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); async Task RequestHandler(HttpContext httpContext) { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -128,7 +129,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -178,7 +179,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt index 4709bfb0befa..945e404522d7 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapPost_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -89,8 +90,8 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var serviceProviderIsService = serviceProvider.GetRequiredService(); var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo)), - (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.TestService)), + (false, typeof(Microsoft.AspNetCore.Http.Generators.Tests.Todo)), + (false, typeof(Microsoft.AspNetCore.Http.Generators.Tests.TestService)), }; foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) { @@ -109,7 +110,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.Todo arg0, global::Microsoft.AspNetCore.Http.Generators.Tests.TestService arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.Todo arg0, Microsoft.AspNetCore.Http.Generators.Tests.TestService arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -128,8 +129,8 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serviceProviderIsService = serviceProvider?.GetService(); - var todo_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "Todo", "todo", serviceProviderIsService); - var svc_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "TestService", "svc", serviceProviderIsService); + var todo_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "Todo", "todo", serviceProviderIsService); + var svc_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "TestService", "svc", serviceProviderIsService); async Task RequestHandler(HttpContext httpContext) { @@ -181,7 +182,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local!, svc_local!)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, todo_local!, svc_local!)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -189,7 +190,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt index 1b6eed872714..763ca3abbcca 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpRequest arg0, global::Microsoft.AspNetCore.Http.HttpResponse arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpRequest arg0, Microsoft.AspNetCore.Http.HttpResponse arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -138,7 +139,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local, res_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local, res_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -146,7 +147,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt index 8a1fa3601b3b..e1b1206cb224 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String arg0, global::System.String arg1) => throw null!); + var handler = Cast(del, System.String (System.String arg0, System.String arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -172,7 +173,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p1_local, p2_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p1_local, p2_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -180,7 +181,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt index 442cb054a677..c1bd48daf26c 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String () => throw null!); + var handler = Cast(del, System.String () => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt index 442cb054a677..c1bd48daf26c 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String () => throw null!); + var handler = Cast(del, System.String () => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt index b27c5510d086..3ebe3609cf34 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(Microsoft.AspNetCore.Http.Generators.Tests.Todo), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::Microsoft.AspNetCore.Http.Generators.Tests.Todo () => throw null!); + var handler = Cast(del, Microsoft.AspNetCore.Http.Generators.Tests.Todo () => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -113,7 +114,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.Todo)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(Microsoft.AspNetCore.Http.Generators.Tests.Todo)); Task RequestHandler(HttpContext httpContext) { @@ -143,7 +144,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt index 25b842275978..4ff050b3a69f 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); + PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::Microsoft.AspNetCore.Http.HttpResults.ValidationProblem () => throw null!); + var handler = Cast(del, Microsoft.AspNetCore.Http.HttpResults.ValidationProblem () => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -139,7 +140,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt index 1dcc34184bb7..d0f46737ff1e 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -139,7 +140,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt index 611e9dfede54..1d6f03114acd 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.TryParseTodo arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -178,7 +179,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt index b47585bdc4ae..0923ec79115b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.TodoStatus arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -178,7 +179,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt index 2a728e60002a..685133fde2df 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String? arg0) => throw null!); + var handler = Cast(del, System.String (System.String? arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -144,7 +145,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -152,7 +153,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt index e5b6afcfaaf9..ab41eacf129c 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapPost_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -89,7 +90,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var serviceProviderIsService = serviceProvider.GetRequiredService(); var jsonBodyOrServiceTypeTuples = new (bool, Type)[] { - (false, typeof(global::Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter)), + (false, typeof(Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter)), }; foreach (var (isOptional, type) in jsonBodyOrServiceTypeTuples) { @@ -101,8 +102,8 @@ namespace Microsoft.AspNetCore.Http.Generated } var parameterInfos = methodInfo.GetParameters(); var x_ParameterInfo = parameterInfos[0]; - PopulateMetadataForParameter(x_ParameterInfo, options.EndpointBuilder); - PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); + PopulateMetadataForParameter(x_ParameterInfo, options.EndpointBuilder); + PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -111,7 +112,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter arg0) => throw null!); + var handler = Cast(del, void (Microsoft.AspNetCore.Http.Generators.Tests.CustomMetadataEmitter arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -121,7 +122,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - handler(ic.GetArgument(0)!); + handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); }, options.EndpointBuilder, @@ -131,7 +132,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serviceProviderIsService = serviceProvider?.GetService(); - var x_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "CustomMetadataEmitter", "x", serviceProviderIsService); + var x_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "CustomMetadataEmitter", "x", serviceProviderIsService); async Task RequestHandler(HttpContext httpContext) { @@ -167,7 +168,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, x_local!)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, x_local!)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -175,7 +176,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt index 2d578a603942..1a9e7fe888f3 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,18 +70,18 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Collections.Generic.IEnumerable httpMethods, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapMethods_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + IEnumerable httpMethods, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.String (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -127,7 +128,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -149,7 +150,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -157,7 +158,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -169,7 +170,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -177,7 +178,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt index 2d578a603942..1a9e7fe888f3 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,18 +70,18 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Collections.Generic.IEnumerable httpMethods, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapMethods_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + IEnumerable httpMethods, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.String (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -127,7 +128,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -149,7 +150,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -157,7 +158,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -169,7 +170,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -177,7 +178,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index 2d578a603942..1a9e7fe888f3 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,18 +70,18 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Collections.Generic.IEnumerable httpMethods, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapMethods_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + IEnumerable httpMethods, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.String (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -127,7 +128,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -149,7 +150,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -157,7 +158,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -169,7 +170,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -177,7 +178,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index 2d578a603942..1a9e7fe888f3 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,18 +70,18 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapMethods_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Collections.Generic.IEnumerable httpMethods, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapMethods_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + IEnumerable httpMethods, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.String (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -127,7 +128,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -149,7 +150,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -157,7 +158,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -169,7 +170,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -177,7 +178,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index e8e33bf39a43..ef9c95dd866f 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapPost_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.String (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -118,7 +119,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -126,7 +127,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -156,7 +157,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -168,7 +169,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -176,7 +177,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt index c13fc9f5851b..1ce6747a0ed6 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,24 +70,24 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapPost_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { Debug.Assert(options != null, "RequestDelegateFactoryOptions not found."); Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 25)); - options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(global::System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); + options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof(System.Int32), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType)); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Int32 (global::System.String[] arg0) => throw null!); + var handler = Cast(del, System.Int32 (System.String[] arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -114,13 +115,13 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions; - var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(global::System.Int32)); + var jsonTypeInfo = (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(System.Int32)); async Task RequestHandler(HttpContext httpContext) { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -128,7 +129,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Generated { var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string[], IsOptional = False, IsParsable = False, IsArray = True, Source = JsonBodyOrQuery) - global::System.String[] p_local = null!; + System.String[] p_local = null!; if (options.DisableInferBodyFromParameters) { var p_raw = httpContext.Request.Query["p"]; @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Http.Generated } else { - var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); + var p_resolveBodyResult = await GeneratedRouteBuilderExtensionsCore.TryResolveBodyAsync(httpContext, logOrThrowExceptionHelper, false, "string[]", "p"); p_local = p_resolveBodyResult.Item2!; if (!p_resolveBodyResult.Item1) { @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, p_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -178,7 +179,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt index 3d0b4dcbb29a..a0030a6530f6 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String () => throw null!); + var handler = Cast(del, System.String () => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -149,11 +150,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static RouteHandlerBuilder MapGet_26( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -169,7 +170,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String () => throw null!); + var handler = Cast(del, System.String () => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -214,7 +215,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -223,11 +224,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static RouteHandlerBuilder MapGet_27( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -243,7 +244,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Threading.Tasks.Task () => throw null!); + var handler = Cast(del, System.Threading.Tasks.Task () => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -289,7 +290,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -298,11 +299,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 28, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_28( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 28, 5)] + internal static RouteHandlerBuilder MapGet_28( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -318,7 +319,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.Threading.Tasks.ValueTask () => throw null!); + var handler = Cast(del, System.Threading.Tasks.ValueTask () => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -364,7 +365,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt index 38f70812c409..1d2cc2a7ed57 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_25( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 25, 13)] + internal static RouteHandlerBuilder MapGet_25( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpRequest arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpRequest arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -136,7 +137,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -144,7 +145,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -153,11 +154,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_26( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 26, 5)] + internal static RouteHandlerBuilder MapGet_26( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -173,7 +174,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpResponse arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpResponse arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -183,7 +184,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -214,7 +215,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, res_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, res_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -222,7 +223,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -231,11 +232,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_27( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 27, 5)] + internal static RouteHandlerBuilder MapGet_27( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -251,7 +252,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.HttpRequest arg0, global::Microsoft.AspNetCore.Http.HttpResponse arg1) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.HttpRequest arg0, Microsoft.AspNetCore.Http.HttpResponse arg1) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -261,7 +262,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!, ic.GetArgument(1)!)); }, options.EndpointBuilder, handler.Method); @@ -294,7 +295,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local, res_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, req_local, res_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -302,7 +303,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt index 9a883ac2babe..a96bca046ea1 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 29, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_29( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 29, 5)] + internal static RouteHandlerBuilder MapPost_29( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.HttpContext arg0, global::Microsoft.AspNetCore.Http.IFormFile arg1, global::Microsoft.AspNetCore.Http.IFormFileCollection arg2, global::Microsoft.AspNetCore.Http.IFormCollection arg3, global::Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord arg4) => throw null!); + var handler = Cast(del, void (Microsoft.AspNetCore.Http.HttpContext arg0, Microsoft.AspNetCore.Http.IFormFile arg1, Microsoft.AspNetCore.Http.IFormFileCollection arg2, Microsoft.AspNetCore.Http.IFormCollection arg3, Microsoft.AspNetCore.Http.Generators.Tests.MyTryParseRecord arg4) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - handler(ic.GetArgument(0)!, ic.GetArgument(1)!, ic.GetArgument(2)!, ic.GetArgument(3)!, ic.GetArgument(4)!); + handler(ic.GetArgument(0)!, ic.GetArgument(1)!, ic.GetArgument(2)!, ic.GetArgument(3)!, ic.GetArgument(4)!); return ValueTask.FromResult(Results.Empty); }, options.EndpointBuilder, @@ -235,7 +236,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, file_local!, fileCollection_local!, collection_local!, tryParseRecord_local!)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, httpContext_local, file_local!, fileCollection_local!, collection_local!, tryParseRecord_local!)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -243,7 +244,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt index cbc42622350b..5b98dde51d2e 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Globalization; using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; @@ -69,17 +70,17 @@ namespace Microsoft.AspNetCore.Http.Generated %GENERATEDCODEATTRIBUTE% file static class GeneratedRouteBuilderExtensionsCore { - private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; - private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post }; - private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put }; - private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete }; - private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch }; - - [global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 44, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_44( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) + private static readonly string[] GetVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Get }; + private static readonly string[] PostVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Post }; + private static readonly string[] PutVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Put }; + private static readonly string[] DeleteVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Delete }; + private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; + + [InterceptsLocation(@"TestMapActions.cs", 44, 5)] + internal static RouteHandlerBuilder MapGet_44( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -94,7 +95,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue arg0) => throw null!); + var handler = Cast(del, void (Microsoft.AspNetCore.Http.Generators.Tests.ParameterListWitDefaultValue arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -104,7 +105,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - handler(ic.GetArgument(0)!); + handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); }, options.EndpointBuilder, @@ -126,7 +127,7 @@ namespace Microsoft.AspNetCore.Http.Generated } var Value_raw = (string?)httpContext.Request.RouteValues["Value"]; var Value_temp = (string?)Value_raw; - global::System.Int32 Value_parsed_temp = default; + System.Int32 Value_parsed_temp = default; if (GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_temp_parsed_non_nullable)) { Value_parsed_temp = Value_temp_parsed_non_nullable; @@ -164,7 +165,7 @@ namespace Microsoft.AspNetCore.Http.Generated } var Value_raw = (string?)httpContext.Request.RouteValues["Value"]; var Value_temp = (string?)Value_raw; - global::System.Int32 Value_parsed_temp = default; + System.Int32 Value_parsed_temp = default; if (GeneratedRouteBuilderExtensionsCore.TryParseExplicit(Value_temp!, CultureInfo.InvariantCulture, out var Value_temp_parsed_non_nullable)) { Value_parsed_temp = Value_temp_parsed_non_nullable; @@ -185,7 +186,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -193,7 +194,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -202,11 +203,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 45, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_45( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 45, 5)] + internal static RouteHandlerBuilder MapGet_45( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -221,7 +222,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct arg0) => throw null!); + var handler = Cast(del, void (Microsoft.AspNetCore.Http.Generators.Tests.ParameterListRecordStruct arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -231,7 +232,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - handler(ic.GetArgument(0)!); + handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); }, options.EndpointBuilder, @@ -305,7 +306,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -313,7 +314,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -322,11 +323,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 46, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_46( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 46, 5)] + internal static RouteHandlerBuilder MapGet_46( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -341,7 +342,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext arg0) => throw null!); + var handler = Cast(del, void (Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithHttpContext arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -351,7 +352,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - handler(ic.GetArgument(0)!); + handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); }, options.EndpointBuilder, @@ -396,7 +397,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -404,7 +405,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -413,11 +414,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 47, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost_47( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 47, 5)] + internal static RouteHandlerBuilder MapPost_47( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -434,7 +435,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, global::System.String (global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody arg0) => throw null!); + var handler = Cast(del, System.String (Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithImplicitFromBody arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -444,7 +445,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - return ValueTask.FromResult(handler(ic.GetArgument(0)!)); + return ValueTask.FromResult(handler(ic.GetArgument(0)!)); }, options.EndpointBuilder, handler.Method); @@ -453,7 +454,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serviceProviderIsService = serviceProvider?.GetService(); - var Todo_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "TodoStruct", "Todo", serviceProviderIsService); + var Todo_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "TodoStruct", "Todo", serviceProviderIsService); async Task RequestHandler(HttpContext httpContext) { @@ -499,7 +500,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -507,7 +508,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, @@ -516,11 +517,11 @@ namespace Microsoft.AspNetCore.Http.Generated createRequestDelegate); } -[global::System.Runtime.CompilerServices.InterceptsLocation(@"TestMapActions.cs", 48, 5)] - internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapGet_48( - this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, - [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, - global::System.Delegate handler) +[InterceptsLocation(@"TestMapActions.cs", 48, 5)] + internal static RouteHandlerBuilder MapGet_48( + this IEndpointRouteBuilder endpoints, + [StringSyntax("Route")] string pattern, + Delegate handler) { MetadataPopulator populateMetadata = (methodInfo, options) => { @@ -530,8 +531,8 @@ namespace Microsoft.AspNetCore.Http.Generated options.EndpointBuilder.Metadata.Add(new GeneratedAcceptsMetadata(contentTypes: GeneratedMetadataConstants.JsonContentType)); var parameterInfos = methodInfo.GetParameters(); var Value_ParameterInfo = new PropertyAsParameterInfo(false, typeof(Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType)!.GetProperty("Value")!, typeof(Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType).GetConstructor(new[] { typeof(Microsoft.AspNetCore.Http.HttpContext), typeof(Microsoft.AspNetCore.Http.Generators.Tests.AddsCustomParameterMetadataAsProperty) })?.GetParameters()[1]); - PopulateMetadataForParameter(Value_ParameterInfo, options.EndpointBuilder); - PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); + PopulateMetadataForParameter(Value_ParameterInfo, options.EndpointBuilder); + PopulateMetadataForEndpoint(methodInfo, options.EndpointBuilder); return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; }; RequestDelegateFactoryFunc createRequestDelegate = (del, options, inferredMetadataResult) => @@ -540,7 +541,7 @@ namespace Microsoft.AspNetCore.Http.Generated Debug.Assert(options.EndpointBuilder != null, "EndpointBuilder not found."); Debug.Assert(options.EndpointBuilder.ApplicationServices != null, "ApplicationServices not found."); Debug.Assert(options.EndpointBuilder.FilterFactories != null, "FilterFactories not found."); - var handler = Cast(del, void (global::Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType arg0) => throw null!); + var handler = Cast(del, void (Microsoft.AspNetCore.Http.Generators.Tests.ParametersListWithMetadataType arg0) => throw null!); EndpointFilterDelegate? filteredInvocation = null; if (options.EndpointBuilder.FilterFactories.Count > 0) { @@ -550,7 +551,7 @@ namespace Microsoft.AspNetCore.Http.Generated { return ValueTask.FromResult(Results.Empty); } - handler(ic.GetArgument(0)!); + handler(ic.GetArgument(0)!); return ValueTask.FromResult(Results.Empty); }, options.EndpointBuilder, @@ -560,7 +561,7 @@ namespace Microsoft.AspNetCore.Http.Generated var serviceProvider = options.ServiceProvider ?? options.EndpointBuilder.ApplicationServices; var logOrThrowExceptionHelper = new LogOrThrowExceptionHelper(serviceProvider, options); var serviceProviderIsService = serviceProvider?.GetService(); - var Value_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "AddsCustomParameterMetadataAsProperty", "Value", serviceProviderIsService); + var Value_JsonBodyOrServiceResolver = ResolveJsonBodyOrService(logOrThrowExceptionHelper, "AddsCustomParameterMetadataAsProperty", "Value", serviceProviderIsService); async Task RequestHandler(HttpContext httpContext) { @@ -604,7 +605,7 @@ namespace Microsoft.AspNetCore.Http.Generated { httpContext.Response.StatusCode = 400; } - var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); + var result = await filteredInvocation(EndpointFilterInvocationContext.Create(httpContext, args_local)); await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); } @@ -612,7 +613,7 @@ namespace Microsoft.AspNetCore.Http.Generated var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection.Empty; return new RequestDelegateResult(targetDelegate, metadata); }; - return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore( + return GeneratedRouteBuilderExtensionsCore.MapCore( endpoints, pattern, handler, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs index 8a90145507ae..761a9e084120 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs @@ -346,7 +346,7 @@ internal async Task VerifyAgainstBaselineUsingFile(Compilation compilation, [Cal .Replace(RequestDelegateGeneratorSources.GeneratedCodeAttribute, "%GENERATEDCODEATTRIBUTE%") + Environment.NewLine; await File.WriteAllTextAsync(baselineFilePath, newSource); - // Assert.Fail("RegenerateBaselines=true. Do not merge PRs with this set."); + Assert.Fail("RegenerateBaselines=true. Do not merge PRs with this set."); } var baseline = await File.ReadAllTextAsync(baselineFilePath); From aef2ba508118ba47c39e64eccddbea4a20ac226c Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Sat, 3 Jun 2023 17:58:20 -0700 Subject: [PATCH 3/7] Add tests for multiple Map calls on one line --- .../gen/RequestDelegateGenerator.cs | 4 +- .../gen/StaticRouteHandler/Model/Endpoint.cs | 2 +- ...MapAction_BindAsync_Snapshot.generated.txt | 40 +++++++++---------- ...Param_ComplexReturn_Snapshot.generated.txt | 4 +- ...Header_ComplexTypeArrayParam.generated.txt | 2 +- ...der_NullableStringArrayParam.generated.txt | 2 +- ...licitHeader_StringArrayParam.generated.txt | 2 +- ...tQuery_ComplexTypeArrayParam.generated.txt | 2 +- ...ery_NullableStringArrayParam.generated.txt | 2 +- ...plicitQuery_StringArrayParam.generated.txt | 2 +- ...eParam_SimpleReturn_Snapshot.generated.txt | 6 +-- ...Source_SimpleReturn_Snapshot.generated.txt | 10 ++--- ...tQuery_ComplexTypeArrayParam.generated.txt | 2 +- ...ery_NullableStringArrayParam.generated.txt | 2 +- ...gArrayParam_EmptyQueryValues.generated.txt | 2 +- ...ngArrayParam_QueryNotPresent.generated.txt | 2 +- ...plicitQuery_StringArrayParam.generated.txt | 2 +- ...ce_HandlesBothJsonAndService.generated.txt | 2 +- ...pecialTypeParam_StringReturn.generated.txt | 2 +- ...ipleStringParam_StringReturn.generated.txt | 2 +- ...aram_StringReturn_WithFilter.generated.txt | 2 +- ...n_ReturnsString_Has_Metadata.generated.txt | 2 +- ...ion_ReturnsTodo_Has_Metadata.generated.txt | 2 +- ...onProblemResult_Has_Metadata.generated.txt | 2 +- ..._ReturnsVoid_Has_No_Metadata.generated.txt | 2 +- ...omplexTypeParam_StringReturn.generated.txt | 2 +- ...SingleEnumParam_StringReturn.generated.txt | 2 +- ...ngValueProvided_StringReturn.generated.txt | 2 +- ...MetadataEmitter_Has_Metadata.generated.txt | 2 +- ...AndBody_ShouldUseQueryString.generated.txt | 2 +- ...AndBody_ShouldUseQueryString.generated.txt | 2 +- ...String_AndBody_ShouldUseBody.generated.txt | 2 +- ...String_AndBody_ShouldUseBody.generated.txt | 2 +- ...String_AndBody_ShouldUseBody.generated.txt | 2 +- ...hArrayQueryString_ShouldFail.generated.txt | 2 +- ...pAction_NoParam_StringReturn.generated.txt | 8 ++-- ...tion_WithParams_StringReturn.generated.txt | 6 +-- ...ateValidateGeneratedFormCode.generated.txt | 2 +- .../VerifyAsParametersBaseline.generated.txt | 10 ++--- .../CompileTimeCreationTests.cs | 23 +++++++++++ 40 files changed, 98 insertions(+), 75 deletions(-) diff --git a/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs b/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs index 781b00a7c681..02b26bcfda08 100644 --- a/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs +++ b/src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs @@ -60,8 +60,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context) { using var stringWriter = new StringWriter(CultureInfo.InvariantCulture); using var codeWriter = new CodeWriter(stringWriter, baseIndent: 2); - codeWriter.WriteLine($$"""[InterceptsLocation(@"{{endpoint.Location.File}}", {{endpoint.Location.LineNumber}}, {{endpoint.Location.CharacterNumber + 1}})]"""); - codeWriter.WriteLine($"internal static RouteHandlerBuilder {endpoint.HttpMethod}_{endpoint.Location.LineNumber}("); + codeWriter.WriteLine($$"""[InterceptsLocation(@"{{endpoint.Location.File}}", {{endpoint.Location.LineNumber}}, {{endpoint.Location.CharacterNumber}})]"""); + codeWriter.WriteLine($"internal static RouteHandlerBuilder {endpoint.HttpMethod}_{endpoint.Location.LineNumber}_{endpoint.Location.CharacterNumber}("); codeWriter.Indent++; codeWriter.WriteLine("this IEndpointRouteBuilder endpoints,"); // MapFallback overloads that only take a delegate do not need a pattern argument diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs index da10a2cec3e6..83ca28231a57 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Model/Endpoint.cs @@ -146,7 +146,7 @@ private static (string, int, int) GetLocation(IInvocationOperation operation) var lineNumber = span.StartLinePosition.Line + 1; // Calculate the character offset to the end of the Map invocation detected var invocationLength = ((MemberAccessExpressionSyntax)((InvocationExpressionSyntax)operation.Syntax).Expression).Expression.Span.Length; - var characterNumber = span.StartLinePosition.Character + invocationLength + 1; + var characterNumber = span.StartLinePosition.Character + invocationLength + 2; return (filePath, lineNumber, characterNumber); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt index 01c4f0b22cd9..ec4b46638f2f 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static RouteHandlerBuilder MapGet_26( + internal static RouteHandlerBuilder MapGet_26_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -265,7 +265,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static RouteHandlerBuilder MapGet_27( + internal static RouteHandlerBuilder MapGet_27_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -370,7 +370,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 28, 5)] - internal static RouteHandlerBuilder MapGet_28( + internal static RouteHandlerBuilder MapGet_28_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -453,7 +453,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 29, 5)] - internal static RouteHandlerBuilder MapGet_29( + internal static RouteHandlerBuilder MapGet_29_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -558,7 +558,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 30, 5)] - internal static RouteHandlerBuilder MapGet_30( + internal static RouteHandlerBuilder MapGet_30_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -641,7 +641,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 31, 5)] - internal static RouteHandlerBuilder MapGet_31( + internal static RouteHandlerBuilder MapGet_31_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -746,7 +746,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 32, 5)] - internal static RouteHandlerBuilder MapGet_32( + internal static RouteHandlerBuilder MapGet_32_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -829,7 +829,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 33, 5)] - internal static RouteHandlerBuilder MapGet_33( + internal static RouteHandlerBuilder MapGet_33_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -933,7 +933,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 34, 5)] - internal static RouteHandlerBuilder MapGet_34( + internal static RouteHandlerBuilder MapGet_34_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1015,7 +1015,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 35, 5)] - internal static RouteHandlerBuilder MapGet_35( + internal static RouteHandlerBuilder MapGet_35_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1119,7 +1119,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 36, 5)] - internal static RouteHandlerBuilder MapGet_36( + internal static RouteHandlerBuilder MapGet_36_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1201,7 +1201,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 37, 5)] - internal static RouteHandlerBuilder MapGet_37( + internal static RouteHandlerBuilder MapGet_37_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1306,7 +1306,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 38, 5)] - internal static RouteHandlerBuilder MapGet_38( + internal static RouteHandlerBuilder MapGet_38_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1389,7 +1389,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 39, 5)] - internal static RouteHandlerBuilder MapGet_39( + internal static RouteHandlerBuilder MapGet_39_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1493,7 +1493,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 40, 5)] - internal static RouteHandlerBuilder MapGet_40( + internal static RouteHandlerBuilder MapGet_40_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1575,7 +1575,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 41, 5)] - internal static RouteHandlerBuilder MapGet_41( + internal static RouteHandlerBuilder MapGet_41_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1680,7 +1680,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 42, 5)] - internal static RouteHandlerBuilder MapGet_42( + internal static RouteHandlerBuilder MapGet_42_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1763,7 +1763,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 43, 5)] - internal static RouteHandlerBuilder MapGet_43( + internal static RouteHandlerBuilder MapGet_43_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -1867,7 +1867,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 44, 5)] - internal static RouteHandlerBuilder MapGet_44( + internal static RouteHandlerBuilder MapGet_44_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt index e45aab4bddee..dba5e18b9b11 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitBodyParam_ComplexReturn_Snapshot.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapPost_25( + internal static RouteHandlerBuilder MapPost_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static RouteHandlerBuilder MapPost_27( + internal static RouteHandlerBuilder MapPost_27_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt index 37680ead65f9..b63dd5401dfa 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt index 08796ffb7c93..3d98ae04182a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt index c78aa1f82302..d6ca14083d3b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt index 5c1005e041b9..01449bcee392 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt index b56f670c5ce5..b41e5b745826 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt index 8322cd1fbaa6..fb97ce9b2385 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt index 5d2b7e12e851..394f619a8610 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static RouteHandlerBuilder MapGet_26( + internal static RouteHandlerBuilder MapGet_26_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -241,7 +241,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static RouteHandlerBuilder MapGet_27( + internal static RouteHandlerBuilder MapGet_27_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt index 4caaffa6cbe0..7f3d6ba7257a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static RouteHandlerBuilder MapGet_26( + internal static RouteHandlerBuilder MapGet_26_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -269,7 +269,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static RouteHandlerBuilder MapGet_27( + internal static RouteHandlerBuilder MapGet_27_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -373,7 +373,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 28, 5)] - internal static RouteHandlerBuilder MapGet_28( + internal static RouteHandlerBuilder MapGet_28_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -470,7 +470,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 29, 5)] - internal static RouteHandlerBuilder MapGet_29( + internal static RouteHandlerBuilder MapGet_29_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt index a5f0367e2680..3fdd0555c49e 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt index 89ba418bb23d..16351b593ffa 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt index 89ba418bb23d..16351b593ffa 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt index 89ba418bb23d..16351b593ffa 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt index b632986d8106..4b1d3faeea24 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt index 945e404522d7..88236349cef1 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapPost_25( + internal static RouteHandlerBuilder MapPost_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt index 763ca3abbcca..022dfea76bf2 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt index e1b1206cb224..84ab4812e398 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt index c1bd48daf26c..d1a91a4c35d4 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt index c1bd48daf26c..d1a91a4c35d4 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt index 3ebe3609cf34..ea3907ae971b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt index 4ff050b3a69f..5df72e93bb51 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsValidationProblemResult_Has_Metadata.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt index d0f46737ff1e..932e4d144376 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsVoid_Has_No_Metadata.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt index 1d6f03114acd..225221e7de75 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt index 0923ec79115b..7064e0b88629 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt index 685133fde2df..80ede01cf9be 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt index ab41eacf129c..400dea4e9c28 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TakesCustomMetadataEmitter_Has_Metadata.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapPost_25( + internal static RouteHandlerBuilder MapPost_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt index 1a9e7fe888f3..d111929a651a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapMethods_25( + internal static RouteHandlerBuilder MapMethods_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, IEnumerable httpMethods, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt index 1a9e7fe888f3..d111929a651a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapMethods_25( + internal static RouteHandlerBuilder MapMethods_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, IEnumerable httpMethods, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index 1a9e7fe888f3..d111929a651a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapMethods_25( + internal static RouteHandlerBuilder MapMethods_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, IEnumerable httpMethods, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index 1a9e7fe888f3..d111929a651a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapMethods_25( + internal static RouteHandlerBuilder MapMethods_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, IEnumerable httpMethods, diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index ef9c95dd866f..66a8a490d870 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapPost_25( + internal static RouteHandlerBuilder MapPost_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt index 1ce6747a0ed6..3a644736c167 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapPost_25( + internal static RouteHandlerBuilder MapPost_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt index a0030a6530f6..a63b7a2475a3 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static RouteHandlerBuilder MapGet_26( + internal static RouteHandlerBuilder MapGet_26_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -225,7 +225,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static RouteHandlerBuilder MapGet_27( + internal static RouteHandlerBuilder MapGet_27_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -300,7 +300,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 28, 5)] - internal static RouteHandlerBuilder MapGet_28( + internal static RouteHandlerBuilder MapGet_28_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt index 1d2cc2a7ed57..107cad1d8bc6 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 25, 13)] - internal static RouteHandlerBuilder MapGet_25( + internal static RouteHandlerBuilder MapGet_25_13( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 26, 5)] - internal static RouteHandlerBuilder MapGet_26( + internal static RouteHandlerBuilder MapGet_26_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 27, 5)] - internal static RouteHandlerBuilder MapGet_27( + internal static RouteHandlerBuilder MapGet_27_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt index a96bca046ea1..e8233988aa02 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/RequestDelegateValidateGeneratedFormCode.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 29, 5)] - internal static RouteHandlerBuilder MapPost_29( + internal static RouteHandlerBuilder MapPost_29_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt index 5b98dde51d2e..1ed66a2804ed 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Http.Generated private static readonly string[] PatchVerb = new[] { Microsoft.AspNetCore.Http.HttpMethods.Patch }; [InterceptsLocation(@"TestMapActions.cs", 44, 5)] - internal static RouteHandlerBuilder MapGet_44( + internal static RouteHandlerBuilder MapGet_44_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 45, 5)] - internal static RouteHandlerBuilder MapGet_45( + internal static RouteHandlerBuilder MapGet_45_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -324,7 +324,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 46, 5)] - internal static RouteHandlerBuilder MapGet_46( + internal static RouteHandlerBuilder MapGet_46_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -415,7 +415,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 47, 5)] - internal static RouteHandlerBuilder MapPost_47( + internal static RouteHandlerBuilder MapPost_47_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) @@ -518,7 +518,7 @@ namespace Microsoft.AspNetCore.Http.Generated } [InterceptsLocation(@"TestMapActions.cs", 48, 5)] - internal static RouteHandlerBuilder MapGet_48( + internal static RouteHandlerBuilder MapGet_48_5( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Delegate handler) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/CompileTimeCreationTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/CompileTimeCreationTests.cs index 21f0bc9eb83a..dd8cf9b746cf 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/CompileTimeCreationTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/CompileTimeCreationTests.cs @@ -62,4 +62,27 @@ public async Task MapAction_SupportsParametersWithDifferingNullability() await VerifyResponseBodyAsync(httpContext, "Hello world!"); } } + + [Fact] + public async Task MapAction_SupportsMultipleMapsOnTheSameLine() + { + var source = """ +app.MapGet("/hello", (string name) => $"Hello {name}!"); app.MapGet("/hello2", (string? name) => $"Hello {name ?? string.Empty}!"); +"""; + var (result, compilation) = await RunGeneratorAsync(source); + var endpoints = GetEndpointsFromCompilation(compilation); + + foreach (var endpoint in endpoints) + { + var httpContext = CreateHttpContext(); + httpContext.Request.Query = new QueryCollection(new Dictionary() + { + { + "name", "world" + } + }); + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "Hello world!"); + } + } } From e7a95d3c8fb5e37740f65e01aebd84fc522b3147 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 13 Jun 2023 13:14:26 -0700 Subject: [PATCH 4/7] Updte Roslyn versions to bring in interceptors feature --- Directory.Build.props | 1 - eng/Versions.props | 20 +++++++++---------- .../RequestDelegateCreationTestBase.cs | 9 +++++---- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index c2bc06baaa24..e5a2b95bfab1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,7 +13,6 @@ true latest Default - /Users/captainsafia/repos/roslyn/artifacts/packages/Release/Shipping diff --git a/eng/Versions.props b/eng/Versions.props index 90c152d133db..02280a1f69ba 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -144,10 +144,10 @@ 8.0.0-preview.6.23312.10 8.0.0-preview.6.23312.10 - 4.7.0-dev - 4.7.0-dev - 4.7.0-dev - 4.7.0-dev + 4.7.0-3.23313.4 + 4.7.0-3.23313.4 + 4.7.0-3.23313.4 + 4.7.0-3.23313.4 6.2.2 @@ -239,13 +239,11 @@ 3.3.1 - 4.7.0-dev - 4.7.0-dev - 4.7.0-dev - 4.7.0-dev - 4.7.0-dev - true - 4.7.0-dev + 4.7.0-3.23313.4 + 4.7.0-3.23313.4 + 4.7.0-3.23313.4 + 4.7.0-3.23313.4 + 4.7.0-3.23313.4 3.3.3 1.1.2-beta1.22531.1 1.1.2-beta1.22531.1 diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs index 761a9e084120..4c08f71804f6 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs @@ -31,6 +31,7 @@ public abstract class RequestDelegateCreationTestBase : LoggedTest protected abstract bool IsGeneratorEnabled { get; } + private static readonly CSharpParseOptions _parseOptions = new CSharpParseOptions(LanguageVersion.Preview).WithFeatures(new[] { new KeyValuePair("InterceptorsPreview", "") }); private static readonly Project _baseProject = CreateProject(); internal async Task<(GeneratorRunResult?, Compilation)> RunGeneratorAsync(string sources, params string[] updatedSources) @@ -54,12 +55,12 @@ public abstract class RequestDelegateCreationTestBase : LoggedTest generator }, driverOptions: new GeneratorDriverOptions(IncrementalGeneratorOutputKind.None, trackIncrementalGeneratorSteps: true), - parseOptions: new CSharpParseOptions(LanguageVersion.Preview)); + parseOptions: _parseOptions); driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var updatedCompilation, out var _); foreach (var updatedSource in updatedSources) { - var syntaxTree = CSharpSyntaxTree.ParseText(GetMapActionString(updatedSource), path: $"TestMapActions.cs", options: new CSharpParseOptions(LanguageVersion.Preview)); + var syntaxTree = CSharpSyntaxTree.ParseText(GetMapActionString(updatedSource), path: $"TestMapActions.cs", options: _parseOptions); compilation = compilation .ReplaceSyntaxTree(compilation.SyntaxTrees.First(), syntaxTree); driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out updatedCompilation, @@ -133,7 +134,7 @@ internal Endpoint[] GetEndpointsFromCompilation(Compilation compilation, bool? e var sourceText = SourceText.From(buffer, buffer.Length, encoding, canBeEmbedded: true); var syntaxRootNode = (CSharpSyntaxNode)syntaxTree.GetRoot(); - var newSyntaxTree = CSharpSyntaxTree.Create(syntaxRootNode, options: new CSharpParseOptions(LanguageVersion.Preview), encoding: encoding, path: syntaxTree.FilePath); + var newSyntaxTree = CSharpSyntaxTree.Create(syntaxRootNode, options: _parseOptions, encoding: encoding, path: syntaxTree.FilePath); compilation = compilation.ReplaceSyntaxTree(syntaxTree, newSyntaxTree); @@ -300,7 +301,7 @@ private static Project CreateProject() .AddProject(projectName, projectName, LanguageNames.CSharp) .WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) .WithNullableContextOptions(NullableContextOptions.Enable)) - .WithParseOptions(new CSharpParseOptions(LanguageVersion.Preview)); + .WithParseOptions(_parseOptions); // Add in required metadata references var resolver = new AppLocalResolver(); From 523c9163ad7e73fd244fb2f592d711b8b7c2121e Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 13 Jun 2023 15:27:08 -0700 Subject: [PATCH 5/7] Fix relocated source files --- .../Emitters/EndpointEmitter.cs | 7 +- .../Emitters/EndpointResponseEmitter.cs | 21 +- ...MapAction_BindAsync_Snapshot.generated.txt | 180 ++++++++++++++++-- ...Header_ComplexTypeArrayParam.generated.txt | 1 - ...der_NullableStringArrayParam.generated.txt | 1 - ...licitHeader_StringArrayParam.generated.txt | 1 - ...tQuery_ComplexTypeArrayParam.generated.txt | 1 - ...ery_NullableStringArrayParam.generated.txt | 1 - ...plicitQuery_StringArrayParam.generated.txt | 1 - ...eParam_SimpleReturn_Snapshot.generated.txt | 27 ++- ...Source_SimpleReturn_Snapshot.generated.txt | 45 ++++- ...tQuery_ComplexTypeArrayParam.generated.txt | 1 - ...ery_NullableStringArrayParam.generated.txt | 1 - ...gArrayParam_EmptyQueryValues.generated.txt | 1 - ...ngArrayParam_QueryNotPresent.generated.txt | 1 - ...plicitQuery_StringArrayParam.generated.txt | 1 - ...ce_HandlesBothJsonAndService.generated.txt | 9 +- ...pecialTypeParam_StringReturn.generated.txt | 9 +- ...ipleStringParam_StringReturn.generated.txt | 9 +- ...aram_StringReturn_WithFilter.generated.txt | 9 +- ...n_ReturnsString_Has_Metadata.generated.txt | 9 +- ...ion_ReturnsTodo_Has_Metadata.generated.txt | 1 - ...omplexTypeParam_StringReturn.generated.txt | 9 +- ...SingleEnumParam_StringReturn.generated.txt | 9 +- ...ngValueProvided_StringReturn.generated.txt | 9 +- ...AndBody_ShouldUseQueryString.generated.txt | 9 +- ...AndBody_ShouldUseQueryString.generated.txt | 9 +- ...String_AndBody_ShouldUseBody.generated.txt | 9 +- ...String_AndBody_ShouldUseBody.generated.txt | 9 +- ...String_AndBody_ShouldUseBody.generated.txt | 9 +- ...hArrayQueryString_ShouldFail.generated.txt | 1 - ...pAction_NoParam_StringReturn.generated.txt | 36 +++- ...tion_WithParams_StringReturn.generated.txt | 27 ++- .../VerifyAsParametersBaseline.generated.txt | 9 +- 34 files changed, 414 insertions(+), 68 deletions(-) diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs index bed29c7def55..24112c375e49 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointEmitter.cs @@ -85,10 +85,6 @@ public static void EmitRequestHandler(this Endpoint endpoint, CodeWriter codeWri { return; } - if (!endpoint.Response.HasNoResponse && endpoint.Response is { ContentType: { } contentType }) - { - codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""{contentType}"";"); - } if (!endpoint.Response.HasNoResponse) { codeWriter.Write("var result = "); @@ -98,6 +94,9 @@ public static void EmitRequestHandler(this Endpoint endpoint, CodeWriter codeWri codeWriter.Write("await "); } codeWriter.WriteLine($"handler({endpoint.EmitArgumentList()});"); + + endpoint.Response.EmitHttpResponseContentType(codeWriter); + if (!endpoint.Response.HasNoResponse) { codeWriter.WriteLine(endpoint.Response.EmitResponseWritingCall(endpoint.IsAwaitable)); diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs index 433c1fddb377..a635b150c723 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EndpointResponseEmitter.cs @@ -11,7 +11,7 @@ internal static void EmitJsonPreparation(this EndpointResponse endpointResponse, { if (endpointResponse.IsSerializableJsonResponse(out var responseType)) { - var typeName = responseType.ToDisplayString(EmitterConstants.DisplayFormat); + var typeName = responseType.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability); codeWriter.WriteLine("var serializerOptions = serviceProvider?.GetService>()?.Value.SerializerOptions ?? new JsonOptions().SerializerOptions;"); codeWriter.WriteLine($"var jsonTypeInfo = (JsonTypeInfo<{typeName}>)serializerOptions.GetTypeInfo(typeof({typeName}));"); @@ -73,7 +73,7 @@ internal static void EmitBuiltinResponseTypeMetadata(this Endpoint endpoint, Cod } else { - codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof({responseType.ToDisplayString(EmitterConstants.DisplayFormat)}), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType));"); + codeWriter.WriteLine($"options.EndpointBuilder.Metadata.Add(new GeneratedProducesResponseTypeMetadata(type: typeof({responseType.ToDisplayString(EmitterConstants.DisplayFormatWithoutNullability)}), statusCode: StatusCodes.Status200OK, contentTypes: GeneratedMetadataConstants.JsonContentType));"); } } @@ -89,4 +89,21 @@ internal static void EmitCallToMetadataProviderForResponse(this Endpoint endpoin codeWriter.WriteLine($"PopulateMetadataForEndpoint<{responseType.ToDisplayString(EmitterConstants.DisplayFormat)}>(methodInfo, options.EndpointBuilder);"); } } + + internal static void EmitHttpResponseContentType(this EndpointResponse endpointResponse, CodeWriter codeWriter) + { + if (!endpointResponse.HasNoResponse + && endpointResponse.ResponseType is { } responseType + && (responseType.SpecialType == SpecialType.System_Object || responseType.SpecialType == SpecialType.System_String)) + { + codeWriter.WriteLine("if (result is string)"); + codeWriter.StartBlock(); + codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""text/plain; charset=utf-8"";"); + codeWriter.EndBlock(); + codeWriter.WriteLine("else"); + codeWriter.StartBlock(); + codeWriter.WriteLine($@"httpContext.Response.ContentType ??= ""application/json; charset=utf-8"";"); + codeWriter.EndBlock(); + } + } } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt index ec4b46638f2f..c390f1c57fa5 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_BindAsync_Snapshot.generated.txt @@ -138,8 +138,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -232,8 +239,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -326,8 +340,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -420,8 +441,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -514,8 +542,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -608,8 +643,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -702,8 +744,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -796,8 +845,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -889,8 +945,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -982,8 +1045,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1075,8 +1145,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1168,8 +1245,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1262,8 +1346,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1356,8 +1447,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1449,8 +1547,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1542,8 +1647,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1636,8 +1748,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1730,8 +1849,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1823,8 +1949,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(httpContext_local, myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -1916,8 +2049,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(myBindAsyncParam_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt index b63dd5401dfa..e0870ac84af9 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_ComplexTypeArrayParam.generated.txt @@ -143,7 +143,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt index 3d98ae04182a..8503c403810d 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_NullableStringArrayParam.generated.txt @@ -130,7 +130,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt index d6ca14083d3b..1b98e5083e18 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitHeader_StringArrayParam.generated.txt @@ -130,7 +130,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt index 01449bcee392..e5e7649ae108 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_ComplexTypeArrayParam.generated.txt @@ -143,7 +143,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt index b41e5b745826..0878e43b79de 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_NullableStringArrayParam.generated.txt @@ -129,7 +129,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt index fb97ce9b2385..e555bef7c674 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitQuery_StringArrayParam.generated.txt @@ -129,7 +129,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt index 394f619a8610..ac0eac5227da 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt @@ -126,8 +126,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(svc_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -208,8 +215,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(svc_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -292,8 +306,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(svc_local, svcs_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt index 7f3d6ba7257a..aa0a43bbfcbb 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt @@ -133,8 +133,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(queryValue_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -229,8 +236,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(headerValue_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -329,8 +343,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(routeValue_local!); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -430,8 +451,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(value_local!); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -527,8 +555,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(value_local!); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt index 3fdd0555c49e..341eb17689dd 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_ComplexTypeArrayParam.generated.txt @@ -144,7 +144,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local!); return httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt index 16351b593ffa..4df90436d56e 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam.generated.txt @@ -142,7 +142,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt index 16351b593ffa..4df90436d56e 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_EmptyQueryValues.generated.txt @@ -142,7 +142,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt index 16351b593ffa..4df90436d56e 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_NullableStringArrayParam_QueryNotPresent.generated.txt @@ -142,7 +142,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt index 4b1d3faeea24..2ce076cd9bea 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ImplicitQuery_StringArrayParam.generated.txt @@ -142,7 +142,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt index 88236349cef1..3faf665054a5 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_JsonBodyOrService_HandlesBothJsonAndService.generated.txt @@ -155,8 +155,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(todo_local!, svc_local!); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt index 022dfea76bf2..b2c1ba21bc95 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleSpecialTypeParam_StringReturn.generated.txt @@ -124,8 +124,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(req_local, res_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt index 84ab4812e398..69709f601b4e 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleStringParam_StringReturn.generated.txt @@ -142,8 +142,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p1_local, p2_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt index d1a91a4c35d4..88e7e027491b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_NoParam_StringReturn_WithFilter.generated.txt @@ -121,8 +121,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt index d1a91a4c35d4..88e7e027491b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsString_Has_Metadata.generated.txt @@ -121,8 +121,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt index ea3907ae971b..78ae19ba9db1 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ReturnsTodo_Has_Metadata.generated.txt @@ -124,7 +124,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(); return GeneratedRouteBuilderExtensionsCore.WriteToResponseAsync(result, httpContext, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt index 225221e7de75..7e9594d4ba7b 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt @@ -141,8 +141,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt index 7064e0b88629..6e3264c8a6ac 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt @@ -141,8 +141,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt index 80ede01cf9be..85b50b0f1254 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn.generated.txt @@ -128,8 +128,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt index d111929a651a..e97e71377612 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Get_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt @@ -141,8 +141,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt index d111929a651a..e97e71377612 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndGet_WithArrayQueryString_AndBody_ShouldUseQueryString.generated.txt @@ -141,8 +141,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index d111929a651a..e97e71377612 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_PostAndPut_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -141,8 +141,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index d111929a651a..e97e71377612 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapMethods_Post_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -141,8 +141,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt index 66a8a490d870..8fdac3b40f96 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_AndBody_ShouldUseBody.generated.txt @@ -140,8 +140,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(p_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt index 3a644736c167..cdc4d2d7fed1 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapPost_WithArrayQueryString_ShouldFail.generated.txt @@ -142,7 +142,6 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "application/json"; var result = handler(p_local); await httpContext.Response.WriteAsJsonAsync(result, jsonTypeInfo); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt index a63b7a2475a3..91e985dba845 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt @@ -121,8 +121,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -195,8 +202,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -270,8 +284,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = await handler(); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } @@ -345,8 +366,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = await handler(); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt index 107cad1d8bc6..40f4fae4c933 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_WithParams_StringReturn.generated.txt @@ -123,8 +123,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(req_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -201,8 +208,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(res_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } @@ -280,8 +294,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return Task.CompletedTask; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(req_local, res_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } return httpContext.Response.WriteAsync(result); } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt index 1ed66a2804ed..b4692cf53c1f 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/VerifyAsParametersBaseline.generated.txt @@ -476,8 +476,15 @@ namespace Microsoft.AspNetCore.Http.Generated httpContext.Response.StatusCode = 400; return; } - httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; var result = handler(args_local); + if (result is string) + { + httpContext.Response.ContentType ??= "text/plain; charset=utf-8"; + } + else + { + httpContext.Response.ContentType ??= "application/json; charset=utf-8"; + } await httpContext.Response.WriteAsync(result); } From c528e8fc1e512e54810ede45d0ab2f9856361ee9 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 13 Jun 2023 16:22:58 -0700 Subject: [PATCH 6/7] Fix build issues in CI --- eng/SourceBuildPrebuiltBaseline.xml | 2 +- eng/Version.Details.xml | 21 ++++--- eng/Versions.props | 20 +++--- .../Microsoft.AspNetCore.App.Analyzers.csproj | 1 + .../src/Analyzers/Resources.resx | 62 +++++++++---------- ...osoft.AspNetCore.App.Analyzers.Test.csproj | 2 + ...entityApiEndpointRouteBuilderExtensions.cs | 2 + ...Core.SignalR.Client.SourceGenerator.csproj | 1 + 8 files changed, 62 insertions(+), 49 deletions(-) diff --git a/eng/SourceBuildPrebuiltBaseline.xml b/eng/SourceBuildPrebuiltBaseline.xml index 915005ae07dd..5e8c3b3f216f 100644 --- a/eng/SourceBuildPrebuiltBaseline.xml +++ b/eng/SourceBuildPrebuiltBaseline.xml @@ -12,7 +12,7 @@ - + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 24a2a1810418..64fbc87c5326 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -194,6 +194,11 @@ 7f9ae67f86a5adc1d9bf2f22f4bf3ec05b6d7b68 + + https://github.com/dotnet/symreader + 27e584661980ee6d82c419a2a471ae505b7d122e + + https://github.com/dotnet/runtime 37c0371ab3f7651d64a6dfe4c2e8677206fa34ee @@ -335,22 +340,22 @@ - + https://github.com/dotnet/roslyn - 65df6b1065bae316232a6c9907a8be995302fb5e + 28075742c870be732a3f20fcfc540a915bc51820 - + https://github.com/dotnet/roslyn - 65df6b1065bae316232a6c9907a8be995302fb5e + 28075742c870be732a3f20fcfc540a915bc51820 - + https://github.com/dotnet/roslyn - 65df6b1065bae316232a6c9907a8be995302fb5e + 28075742c870be732a3f20fcfc540a915bc51820 - + https://github.com/dotnet/roslyn - 65df6b1065bae316232a6c9907a8be995302fb5e + 28075742c870be732a3f20fcfc540a915bc51820 diff --git a/eng/Versions.props b/eng/Versions.props index 02280a1f69ba..21444a387d04 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -144,10 +144,10 @@ 8.0.0-preview.6.23312.10 8.0.0-preview.6.23312.10 - 4.7.0-3.23313.4 - 4.7.0-3.23313.4 - 4.7.0-3.23313.4 - 4.7.0-3.23313.4 + 4.7.0-3.23313.12 + 4.7.0-3.23313.12 + 4.7.0-3.23313.12 + 4.7.0-3.23313.12 6.2.2 @@ -163,6 +163,8 @@ 8.0.0-alpha.1.23305.2 8.0.0-alpha.1.23309.1 + + 2.0.0-beta-23228-03 7.0.0-preview.22423.2 @@ -239,11 +241,11 @@ 3.3.1 - 4.7.0-3.23313.4 - 4.7.0-3.23313.4 - 4.7.0-3.23313.4 - 4.7.0-3.23313.4 - 4.7.0-3.23313.4 + 4.7.0-3.23313.12 + 4.7.0-3.23313.12 + 4.7.0-3.23313.12 + 4.7.0-3.23313.12 + 4.7.0-3.23313.12 3.3.3 1.1.2-beta1.22531.1 1.1.2-beta1.22531.1 diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj index 43d258fb37a2..97439d9a3d20 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj @@ -8,6 +8,7 @@ Enable Microsoft.AspNetCore.Analyzers true + true diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Resources.resx b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Resources.resx index f3a1901a5ff4..c4347a2b8797 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Resources.resx +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Resources.resx @@ -1,17 +1,17 @@ - @@ -211,7 +211,7 @@ Route handler has multiple parameters with the [FromBody] attribute or a parameter with an [AsParameters] attribute where the parameter type contains multiple members with [FromBody] attributes. Only one parameter can have a [FromBody] attribute. - Route handler has multiple parameters with the [FromBody] attribute. + Route handler has multiple parameters with the [FromBody] attribute Do not use model binding attributes with route handlers @@ -289,10 +289,10 @@ Complex types referenced by route parameters must be parsable - Parameter '{0}' of type {1} should define a bool TryParse(string, IFormatProvider, out {1}) method, or implement IParsable<{1}>. + Parameter '{0}' of type {1} should define a bool TryParse(string, IFormatProvider, out {1}) method, or implement IParsable<{1}> - When implementing BindAsync(...) method, the return type must be ValueTask<T>. + When implementing BindAsync(...) method, the return type must be ValueTask<T> Parameter '{0}' of type {1} has a BindAsync(...) method, but the return type is not ValueTask<{1}>. Consider implementing IBindableFromHttpContext<{1}> to enforce implementation. @@ -310,7 +310,7 @@ Route '{0}' conflicts with another action route. An HTTP request that matches multiple routes results in an ambiguous match error. Fix the conflict by changing the route's pattern, HTTP method, or route constraints. - Use AddAuthorizationBuilder to register authorization services and construct policies. + Use AddAuthorizationBuilder to register authorization services and construct policies Use AddAuthorizationBuilder diff --git a/src/Framework/AspNetCoreAnalyzers/test/Microsoft.AspNetCore.App.Analyzers.Test.csproj b/src/Framework/AspNetCoreAnalyzers/test/Microsoft.AspNetCore.App.Analyzers.Test.csproj index 02dc9b4e3d49..5f223d266110 100644 --- a/src/Framework/AspNetCoreAnalyzers/test/Microsoft.AspNetCore.App.Analyzers.Test.csproj +++ b/src/Framework/AspNetCoreAnalyzers/test/Microsoft.AspNetCore.App.Analyzers.Test.csproj @@ -4,6 +4,8 @@ $(DefaultNetCoreTargetFramework) true Microsoft.AspNetCore.Analyzers + + $(NoWarn);RS1036;RS2008 diff --git a/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs b/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs index 11a40a5e74be..3a345434bbb6 100644 --- a/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs +++ b/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs @@ -27,6 +27,8 @@ public static class IdentityApiEndpointRouteBuilderExtensions /// Call to add a prefix to all the endpoints. /// /// An to further customize the added endpoints. + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("AOT", "IL3050", Justification = "This implementation invokes uses compile-time code gen to construct the RequestDelegate.")] + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "This implementation invokes uses compile-time code gen to construct the RequestDelegate.")] public static IEndpointConventionBuilder MapIdentityApi(this IEndpointRouteBuilder endpoints) where TUser : class, new() { ArgumentNullException.ThrowIfNull(endpoints); diff --git a/src/SignalR/clients/csharp/Client.SourceGenerator/src/Microsoft.AspNetCore.SignalR.Client.SourceGenerator.csproj b/src/SignalR/clients/csharp/Client.SourceGenerator/src/Microsoft.AspNetCore.SignalR.Client.SourceGenerator.csproj index 049814d8bc61..4da52ce626de 100644 --- a/src/SignalR/clients/csharp/Client.SourceGenerator/src/Microsoft.AspNetCore.SignalR.Client.SourceGenerator.csproj +++ b/src/SignalR/clients/csharp/Client.SourceGenerator/src/Microsoft.AspNetCore.SignalR.Client.SourceGenerator.csproj @@ -5,6 +5,7 @@ false true false + true From 491f92862a28f564bfcc6d0764d77df19fa150fe Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 13 Jun 2023 19:23:33 -0700 Subject: [PATCH 7/7] Update Versions.props --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index d30bc244a72f..b9b352c8cf5e 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -164,7 +164,7 @@ 8.0.0-alpha.1.23312.2 - 2.0.0-beta-23228-03 + 2.0.0-beta-23228-03 7.0.0-preview.22423.2