From fcb1a8d2677e3f922c70be0bcf54a19959eee671 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Thu, 16 Feb 2023 14:21:00 +1100 Subject: [PATCH 01/11] WIP: End-to-end TryParse. --- .../Emitters/EndpointParameterEmitter.cs | 18 + .../EndpointParameter.cs | 35 + ...Param_ComplexReturn_Snapshot.generated.txt | 24 +- ...tipleInt32Param_StringReturn.generated.txt | 203 +++ ...pecialTypeParam_StringReturn.generated.txt | 24 +- ...ipleStringParam_StringReturn.generated.txt | 36 +- ...aram_StringReturn_WithFilter.generated.txt | 24 +- ...omplexTypeParam_StringReturn.generated.txt | 1624 +++++++++++++++++ ...SingleEnumParam_StringReturn.generated.txt | 1624 +++++++++++++++++ ...ingleInt32Param_StringReturn.generated.txt | 1624 +++++++++++++++++ ...ngValueProvided_StringReturn.generated.txt | 30 +- ...ngValueProvided_StringReturn.generated.txt | 30 +- ...ngValueProvided_StringReturn.generated.txt | 30 +- ...ngleStringParam_StringReturn.generated.txt | 30 +- ...pAction_NoParam_StringReturn.generated.txt | 24 +- ...tion_WithParams_StringReturn.generated.txt | 24 +- .../RequestDelegateGeneratorTests.cs | 87 + 17 files changed, 5359 insertions(+), 132 deletions(-) create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs index 837ee73c4a55..59bdf02dc2de 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs @@ -36,6 +36,7 @@ internal static string EmitQueryOrHeaderParameterPreparation(this EndpointParame { builder.AppendLine($$""" var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.EmitAssigningCodeResult()}}.Count > 0 ? {{endpointParameter.EmitAssigningCodeResult()}}.ToString() : null; + var {{endpointParameter.Name}}_temp = {{endpointParameter.Name}}_raw.Count > 0 ? {{endpointParameter.Name}}_raw.ToString() : null; """); } else @@ -46,6 +47,23 @@ internal static string EmitQueryOrHeaderParameterPreparation(this EndpointParame wasParamCheckFailure = true; } var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.EmitAssigningCodeResult()}}.ToString(); + var {{endpointParameter.Name}}_temp = {{endpointParameter.EmitAssigningCodeResult()}}.ToString(); +"""); + } + + if (endpointParameter.IsParsable) + { + var parsingBlock = endpointParameter.ParsingBlockEmitter($"{endpointParameter.Name}_temp", $"{endpointParameter.Name}_parsed_temp"); + builder.AppendLine($$""" + {{parsingBlock}} + var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.Name}}_parsed_temp!; +"""); + + } + else + { + builder.AppendLine($$""" + var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.Name}}_temp; """); } diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs index ef493e6b6d35..faea6707d463 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs @@ -34,6 +34,9 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp Source = EndpointParameterSource.Query; Name = GetParameterName(fromQueryAttribute, parameter.Name); IsOptional = parameter.IsOptional(); + AssigningCode = $"httpContext.Request.Query[\"{parameter.Name}\"]"; + IsParsable = TryGetParsability(parameter, out var parsingBlockEmitter); + ParsingBlockEmitter = parsingBlockEmitter; } else if (parameter.HasAttributeImplementingInterface(fromHeaderMetadataInterfaceType, out var fromHeaderAttribute)) { @@ -68,6 +71,36 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp } } + private static bool TryGetParsability(IParameterSymbol parameter, [NotNullWhen(true)]out Func? parsingBlockEmitter) + { + if (parameter.Type.SpecialType == SpecialType.System_String) + { + parsingBlockEmitter = default; + return false; + } + else + { + // HACK: This switch will be replaced by a more comprehensive method that will + // return that will return Func that will emit + // the correct TryParse call for each scenario. This is just a stub to + // build out the various test cases and get things working end-to-end. + Func preferredTryParseInvocation = parameter.Type switch + { + { BaseType.SpecialType: SpecialType.System_Enum } => (string inputArgument, string outputArgument) => $$"""Enum.TryParse({{inputArgument}}, out var {{outputArgument}})""", + { SpecialType: SpecialType.System_Int32 } => (string inputArgument, string outputArgument) => $$"""int.TryParse({{inputArgument}}, out var {{outputArgument}})""", + _ => (string inputArgument, string outputArgument) => $$"""global::{{parameter.Type}}.TryParse({{inputArgument}}, out var {{outputArgument}})""" + }; + + parsingBlockEmitter = (inputArgument, outputArgument) => $$""" + if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}}) + { + wasParamCheckFailure = true; + } + """; + return true; + } + } + public ITypeSymbol Type { get; } public EndpointParameterSource Source { get; } @@ -76,6 +109,8 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp internal string? AssigningCode { get; set; } public string Name { get; } public bool IsOptional { get; } + public bool IsParsable { get; } + public Func ParsingBlockEmitter { get; } // TODO: Handle special form types like IFormFileCollection that need special body-reading logic. private static bool TryGetSpecialTypeAssigningCode(ITypeSymbol type, WellKnownTypes wellKnownTypes, [NotNullWhen(true)] out string? callingCode) 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 7523d383cc99..a72de96879f1 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -301,7 +301,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -407,7 +407,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -520,7 +520,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -640,7 +640,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -767,7 +767,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -901,7 +901,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -1042,7 +1042,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1190,7 +1190,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1345,7 +1345,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1507,7 +1507,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt new file mode 100644 index 000000000000..5067cfb25ee2 --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt @@ -0,0 +1,203 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + 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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 15)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 15)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (System.Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + // Endpoint Parameter: p1 (Type = int, IsOptional = False, Source = Query) + var p1_raw = httpContext.Request.Query["p1"]; + if (StringValues.IsNullOrEmpty(p1_raw)) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + if (!int.TryParse(p1_raw, out var p1_local)) +{ + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; +} + + // Endpoint Parameter: p2 (Type = int, IsOptional = False, Source = Query) + var p2_raw = httpContext.Request.Query["p2"]; + if (StringValues.IsNullOrEmpty(p2_raw)) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + if (!int.TryParse(p2_raw, out var p2_local)) +{ + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; +} + + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p1_local, p2_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var result = await filteredInvocation(new DefaultEndpointFilterInvocationContext(httpContext)); + await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); + } + + 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) + { + var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; + return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + } +} \ No newline at end of file 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 12fe9c871b46..ca79acae2d5e 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -330,7 +330,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -443,7 +443,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -563,7 +563,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -690,7 +690,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -824,7 +824,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -965,7 +965,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1113,7 +1113,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1268,7 +1268,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1430,7 +1430,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) 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 d0e6b6258132..bc8cf98b876b 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -119,7 +119,8 @@ namespace Microsoft.AspNetCore.Http.Generated { wasParamCheckFailure = true; } - var p1_local = p1_raw.ToString(); + var p1_temp = p1_raw.ToString(); + var p1_local = p1_temp; // Endpoint Parameter: p2 (Type = global::System.String, IsOptional = False, Source = Query) var p2_raw = httpContext.Request.Query["p2"]; @@ -127,7 +128,8 @@ namespace Microsoft.AspNetCore.Http.Generated { wasParamCheckFailure = true; } - var p2_local = p2_raw.ToString(); + var p2_temp = p2_raw.ToString(); + var p2_local = p2_temp; if (wasParamCheckFailure) { @@ -147,7 +149,8 @@ namespace Microsoft.AspNetCore.Http.Generated { wasParamCheckFailure = true; } - var p1_local = p1_raw.ToString(); + var p1_temp = p1_raw.ToString(); + var p1_local = p1_temp; // Endpoint Parameter: p2 (Type = global::System.String, IsOptional = False, Source = Query) var p2_raw = httpContext.Request.Query["p2"]; @@ -155,7 +158,8 @@ namespace Microsoft.AspNetCore.Http.Generated { wasParamCheckFailure = true; } - var p2_local = p2_raw.ToString(); + var p2_temp = p2_raw.ToString(); + var p2_local = p2_temp; if (wasParamCheckFailure) { @@ -252,7 +256,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -358,7 +362,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -471,7 +475,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -591,7 +595,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -718,7 +722,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -852,7 +856,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -993,7 +997,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1141,7 +1145,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1296,7 +1300,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1458,7 +1462,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) 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 b9924bfcc456..0a70c96913ea 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -328,7 +328,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -441,7 +441,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -561,7 +561,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -688,7 +688,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -822,7 +822,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -963,7 +963,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1111,7 +1111,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1266,7 +1266,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1428,7 +1428,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) 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 new file mode 100644 index 000000000000..a1ea12e615c8 --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt @@ -0,0 +1,1624 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + 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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = TestMapActions.Todo, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::TestMapActions.Todo.TryParse(p_temp, out var p_parsed_temp)) +{ + wasParamCheckFailure = true; +} + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = TestMapActions.Todo, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::TestMapActions.Todo.TryParse(p_temp, out var p_parsed_temp)) +{ + wasParamCheckFailure = true; +} + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} \ No newline at end of file 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 new file mode 100644 index 000000000000..1f6d30494041 --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt @@ -0,0 +1,1624 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + 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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = TestMapActions.TodoStatus, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!Enum.TryParse(p_temp, out var p_parsed_temp)) +{ + wasParamCheckFailure = true; +} + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = TestMapActions.TodoStatus, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!Enum.TryParse(p_temp, out var p_parsed_temp)) +{ + wasParamCheckFailure = true; +} + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt new file mode 100644 index 000000000000..fa51c806582e --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt @@ -0,0 +1,1624 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + 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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = int, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!int.TryParse(p_temp, out var p_parsed_temp)) +{ + wasParamCheckFailure = true; +} + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = int, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!int.TryParse(p_temp, out var p_parsed_temp)) +{ + wasParamCheckFailure = true; +} + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} \ No newline at end of file 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 629831833520..e58f1406adfa 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -115,7 +115,8 @@ namespace Microsoft.AspNetCore.Http.Generated var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = global::System.String?, IsOptional = True, Source = Query) var p_raw = httpContext.Request.Query["p"]; - var p_local = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_local = p_temp; if (wasParamCheckFailure) { @@ -131,7 +132,8 @@ namespace Microsoft.AspNetCore.Http.Generated var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = global::System.String?, IsOptional = True, Source = Query) var p_raw = httpContext.Request.Query["p"]; - var p_local = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_local = p_temp; if (wasParamCheckFailure) { @@ -228,7 +230,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -334,7 +336,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -447,7 +449,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -567,7 +569,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -694,7 +696,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -828,7 +830,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -969,7 +971,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1117,7 +1119,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1272,7 +1274,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1434,7 +1436,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt index 0a88867dc913..58f17086af33 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -115,7 +115,8 @@ namespace Microsoft.AspNetCore.Http.Generated var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?, IsOptional = True, Source = Query) var p_raw = httpContext.Request.Query["p"]; - var p_local = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_local = p_temp; if (wasParamCheckFailure) { @@ -131,7 +132,8 @@ namespace Microsoft.AspNetCore.Http.Generated var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?, IsOptional = True, Source = Query) var p_raw = httpContext.Request.Query["p"]; - var p_local = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_local = p_temp; if (wasParamCheckFailure) { @@ -235,7 +237,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -341,7 +343,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -454,7 +456,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -574,7 +576,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -701,7 +703,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -835,7 +837,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -976,7 +978,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1124,7 +1126,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1279,7 +1281,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1441,7 +1443,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt index 0a88867dc913..58f17086af33 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -115,7 +115,8 @@ namespace Microsoft.AspNetCore.Http.Generated var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?, IsOptional = True, Source = Query) var p_raw = httpContext.Request.Query["p"]; - var p_local = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_local = p_temp; if (wasParamCheckFailure) { @@ -131,7 +132,8 @@ namespace Microsoft.AspNetCore.Http.Generated var wasParamCheckFailure = false; // Endpoint Parameter: p (Type = string?, IsOptional = True, Source = Query) var p_raw = httpContext.Request.Query["p"]; - var p_local = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; + var p_local = p_temp; if (wasParamCheckFailure) { @@ -235,7 +237,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -341,7 +343,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -454,7 +456,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -574,7 +576,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -701,7 +703,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -835,7 +837,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -976,7 +978,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1124,7 +1126,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1279,7 +1281,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1441,7 +1443,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_StringReturn.generated.txt index 87e2f4a1c6ef..820077539c5a 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_StringReturn.generated.txt @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -119,7 +119,8 @@ namespace Microsoft.AspNetCore.Http.Generated { wasParamCheckFailure = true; } - var p_local = p_raw.ToString(); + var p_temp = p_raw.ToString(); + var p_local = p_temp; if (wasParamCheckFailure) { @@ -139,7 +140,8 @@ namespace Microsoft.AspNetCore.Http.Generated { wasParamCheckFailure = true; } - var p_local = p_raw.ToString(); + var p_temp = p_raw.ToString(); + var p_local = p_temp; if (wasParamCheckFailure) { @@ -243,7 +245,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -349,7 +351,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -462,7 +464,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -582,7 +584,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -709,7 +711,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -843,7 +845,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -984,7 +986,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1132,7 +1134,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1287,7 +1289,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1449,7 +1451,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) 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 710b0e849edc..ba7398940a93 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -417,7 +417,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -523,7 +523,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -636,7 +636,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -756,7 +756,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -883,7 +883,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -1017,7 +1017,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -1158,7 +1158,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1306,7 +1306,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1461,7 +1461,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1623,7 +1623,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) 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 e1c2ea654f0f..73f250e2ea36 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -364,7 +364,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -470,7 +470,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -583,7 +583,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -703,7 +703,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -830,7 +830,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -964,7 +964,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -1105,7 +1105,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1253,7 +1253,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1408,7 +1408,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1570,7 +1570,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - %GENERATEDCODEATTRIBUTE% + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs index 8766a3f5e58e..1e3818b7753c 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs @@ -95,6 +95,93 @@ public async Task MapAction_ExplicitQueryParam_StringReturn(string source, strin await VerifyResponseBodyAsync(httpContext, expectedBody, expectedStatusCode); } + [Fact] + public async Task MapAction_SingleInt32Param_StringReturn() + { + var (results, compilation) = await RunGeneratorAsync(""" +app.MapGet("/hello", ([FromQuery]int p) => p.ToString()); +"""); + + var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); + var endpoint = GetEndpointFromCompilation(compilation); + + Assert.Equal("/hello", endpointModel.RoutePattern); + Assert.Equal("MapGet", endpointModel.HttpMethod); + var p = Assert.Single(endpointModel.Parameters); + Assert.Equal(EndpointParameterSource.Query, p.Source); + Assert.Equal("p", p.Name); + + var httpContext = CreateHttpContext(); + httpContext.Request.QueryString = new QueryString("?p=42"); + + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "42"); + await VerifyAgainstBaselineUsingFile(compilation); + } + + [Fact] + public async Task MapAction_SingleComplexTypeParam_StringReturn() + { + // HACK! Notice the return value of p.Name! - this is because TestMapActions.cs has #nullable enable + // set and the compiler is returning when it is simply p.Name: + // + // CS8603: Possible null reference return. + // + // Without source gen this same code isn't a problem. + var (results, compilation) = await RunGeneratorAsync(""" +app.MapGet("/hello", ([FromQuery]Todo p) => p.Name!); +"""); + + var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); + var endpoint = GetEndpointFromCompilation(compilation); + + Assert.Equal("/hello", endpointModel.RoutePattern); + Assert.Equal("MapGet", endpointModel.HttpMethod); + var p = Assert.Single(endpointModel.Parameters); + Assert.Equal(EndpointParameterSource.Query, p.Source); + Assert.Equal("p", p.Name); + + var httpContext = CreateHttpContext(); + httpContext.Request.QueryString = new QueryString("?p=1"); + + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "Knit kitten mittens."); + await VerifyAgainstBaselineUsingFile(compilation); + } + + [Fact] + public async Task MapAction_SingleEnumParam_StringReturn() + { + // HACK! Notice the return value of p.Name! - this is because TestMapActions.cs has #nullable enable + // set and the compiler is returning when it is simply p.Name: + // + // CS8603: Possible null reference return. + // + // Without source gen this same code isn't a problem. + var (results, compilation) = await RunGeneratorAsync(""" +app.MapGet("/hello", ([FromQuery]TodoStatus p) => p.ToString()); +"""); + + var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); + var endpoint = GetEndpointFromCompilation(compilation); + + Assert.Equal("/hello", endpointModel.RoutePattern); + Assert.Equal("MapGet", endpointModel.HttpMethod); + var p = Assert.Single(endpointModel.Parameters); + Assert.Equal(EndpointParameterSource.Query, p.Source); + Assert.Equal("p", p.Name); + + var httpContext = CreateHttpContext(); + httpContext.Request.QueryString = new QueryString("?p=Done"); + + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "Done"); + await VerifyAgainstBaselineUsingFile(compilation); + } + + // [Fact] + // public async Task MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn() + [Fact] public async Task MapAction_SingleNullableStringParam_WithEmptyQueryStringValueProvided_StringReturn() { From dbe320da7b4e72b5b44f41cc3c413a1c38a534b2 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 20 Feb 2023 17:16:25 +1100 Subject: [PATCH 02/11] Handle more parsing scenarios. --- .../Microsoft.AspNetCore.App.Analyzers.csproj | 3 + ...icrosoft.AspNetCore.Http.Generators.csproj | 3 + .../EndpointParameter.cs | 51 ++++---- .../RequestDelegateGeneratorTestBase.cs | 1 + .../RequestDelegateGeneratorTests.cs | 118 +++++++++++++++++- .../RoslynUtils}/Bindability.cs | 0 .../RoslynUtils}/Parsability.cs | 0 .../RoslynUtils}/ParsabilityHelper.cs | 0 8 files changed, 152 insertions(+), 24 deletions(-) rename src/{Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure => Shared/RoslynUtils}/Bindability.cs (100%) rename src/{Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure => Shared/RoslynUtils}/Parsability.cs (100%) rename src/{Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure => Shared/RoslynUtils}/ParsabilityHelper.cs (100%) 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 83c09bcf59a2..5da6960da26a 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj @@ -27,6 +27,9 @@ + + + diff --git a/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.Generators.csproj b/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.Generators.csproj index b791dcb5efd8..ab11f1b015b1 100644 --- a/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.Generators.csproj +++ b/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.Generators.csproj @@ -24,6 +24,9 @@ + + + diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs index faea6707d463..898533dc2d1b 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Analyzers.RouteEmbeddedLanguage.Infrastructure; using Microsoft.CodeAnalysis; using WellKnownType = Microsoft.AspNetCore.App.Analyzers.Infrastructure.WellKnownTypeData.WellKnownType; +using Microsoft.AspNetCore.Analyzers.Infrastructure; namespace Microsoft.AspNetCore.Http.Generators.StaticRouteHandlerModel; @@ -35,7 +36,7 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp Name = GetParameterName(fromQueryAttribute, parameter.Name); IsOptional = parameter.IsOptional(); AssigningCode = $"httpContext.Request.Query[\"{parameter.Name}\"]"; - IsParsable = TryGetParsability(parameter, out var parsingBlockEmitter); + IsParsable = TryGetParsability(parameter, wellKnownTypes, out var parsingBlockEmitter); ParsingBlockEmitter = parsingBlockEmitter; } else if (parameter.HasAttributeImplementingInterface(fromHeaderMetadataInterfaceType, out var fromHeaderAttribute)) @@ -71,34 +72,40 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp } } - private static bool TryGetParsability(IParameterSymbol parameter, [NotNullWhen(true)]out Func? parsingBlockEmitter) + private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKnownTypes, [NotNullWhen(true)]out Func? parsingBlockEmitter) { if (parameter.Type.SpecialType == SpecialType.System_String) { - parsingBlockEmitter = default; + parsingBlockEmitter = null; return false; } - else + + if (ParsabilityHelper.GetParsability(parameter.Type, wellKnownTypes) == Parsability.NotParsable) { - // HACK: This switch will be replaced by a more comprehensive method that will - // return that will return Func that will emit - // the correct TryParse call for each scenario. This is just a stub to - // build out the various test cases and get things working end-to-end. - Func preferredTryParseInvocation = parameter.Type switch - { - { BaseType.SpecialType: SpecialType.System_Enum } => (string inputArgument, string outputArgument) => $$"""Enum.TryParse({{inputArgument}}, out var {{outputArgument}})""", - { SpecialType: SpecialType.System_Int32 } => (string inputArgument, string outputArgument) => $$"""int.TryParse({{inputArgument}}, out var {{outputArgument}})""", - _ => (string inputArgument, string outputArgument) => $$"""global::{{parameter.Type}}.TryParse({{inputArgument}}, out var {{outputArgument}})""" - }; - - parsingBlockEmitter = (inputArgument, outputArgument) => $$""" - if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}}) - { - wasParamCheckFailure = true; - } - """; - return true; + parsingBlockEmitter = null; + return false; + } + + // This is the default TryParse call that we support, but subsequent statements override as appropriate. + var preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, out var {{outputArgument}})"""; + + if (parameter.Type.Implements(wellKnownTypes.Get(WellKnownType.System_IParsable_T))) + { + preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})"""; } + + if (parameter.Type.BaseType.SpecialType == SpecialType.System_Enum) + { + preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""Enum.TryParse<{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}>({{inputArgument}}, out var {{outputArgument}})"""; + } + + parsingBlockEmitter = (inputArgument, outputArgument) => $$""" + if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}}) + { + wasParamCheckFailure = true; + } + """; + return true; } public ITypeSymbol Type { get; } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs index b9a57c00683c..176427059129 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs @@ -248,6 +248,7 @@ internal async Task VerifyAgainstBaselineUsingFile(Compilation compilation, [Cal var baselineFilePath = Path.Combine("RequestDelegateGenerator", "Baselines", $"{callerName}.generated.txt"); var generatedSyntaxTree = compilation.SyntaxTrees.Last(); var generatedCode = await generatedSyntaxTree.GetTextAsync(); + await File.WriteAllTextAsync(baselineFilePath, generatedCode.ToString()); var baseline = await File.ReadAllTextAsync(baselineFilePath); var expectedLines = baseline .TrimEnd() // Trim newlines added by autoformat diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs index 1e3818b7753c..8addd21eb318 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs @@ -96,10 +96,124 @@ public async Task MapAction_ExplicitQueryParam_StringReturn(string source, strin } [Fact] - public async Task MapAction_SingleInt32Param_StringReturn() + public async Task MapAction_SingleDateOnlyParam_StringReturn() { var (results, compilation) = await RunGeneratorAsync(""" -app.MapGet("/hello", ([FromQuery]int p) => p.ToString()); +app.MapGet("/hello", ([FromQuery]DateOnly p) => p.ToString("yyyy-MM-dd")); +"""); + var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); + var endpoint = GetEndpointFromCompilation(compilation); + + Assert.Equal("/hello", endpointModel.RoutePattern); + Assert.Equal("MapGet", endpointModel.HttpMethod); + var p = Assert.Single(endpointModel.Parameters); + Assert.Equal(EndpointParameterSource.Query, p.Source); + Assert.Equal("p", p.Name); + + var httpContext = CreateHttpContext(); + httpContext.Request.QueryString = new QueryString("?p=2023-02-20"); + + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "2023-02-20"); + await VerifyAgainstBaselineUsingFile(compilation); + } + + [Fact] + public async Task MapAction_SingleTimeOnlyParam_StringReturn() + { + var (results, compilation) = await RunGeneratorAsync(""" +app.MapGet("/hello", ([FromQuery]TimeOnly p) => p.ToString()); +"""); + var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); + var endpoint = GetEndpointFromCompilation(compilation); + + Assert.Equal("/hello", endpointModel.RoutePattern); + Assert.Equal("MapGet", endpointModel.HttpMethod); + var p = Assert.Single(endpointModel.Parameters); + Assert.Equal(EndpointParameterSource.Query, p.Source); + Assert.Equal("p", p.Name); + + var httpContext = CreateHttpContext(); + httpContext.Request.QueryString = new QueryString("?p=13:30"); + + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "1:30 PM"); + await VerifyAgainstBaselineUsingFile(compilation); + } + + [Fact] + public async Task MapAction_SingleDateTimeParam_StringReturn() + { + var (results, compilation) = await RunGeneratorAsync(""" +app.MapGet("/hello", ([FromQuery]DateTime p) => p.ToString("yyyy-MM-dd")); +"""); + var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); + var endpoint = GetEndpointFromCompilation(compilation); + + Assert.Equal("/hello", endpointModel.RoutePattern); + Assert.Equal("MapGet", endpointModel.HttpMethod); + var p = Assert.Single(endpointModel.Parameters); + Assert.Equal(EndpointParameterSource.Query, p.Source); + Assert.Equal("p", p.Name); + + var httpContext = CreateHttpContext(); + httpContext.Request.QueryString = new QueryString("?p=2023-02-20"); + + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "2023-02-20"); + await VerifyAgainstBaselineUsingFile(compilation); + } + + [Fact] + public async Task MapAction_SingleDateTimeOffsetParam_StringReturn() + { + var (results, compilation) = await RunGeneratorAsync(""" +app.MapGet("/hello", ([FromQuery]DateTimeOffset p) => p.ToString("yyyy-MM-dd")); +"""); + var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); + var endpoint = GetEndpointFromCompilation(compilation); + + Assert.Equal("/hello", endpointModel.RoutePattern); + Assert.Equal("MapGet", endpointModel.HttpMethod); + var p = Assert.Single(endpointModel.Parameters); + Assert.Equal(EndpointParameterSource.Query, p.Source); + Assert.Equal("p", p.Name); + + var httpContext = CreateHttpContext(); + httpContext.Request.QueryString = new QueryString("?p=2023-02-20"); + + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, "2023-02-20"); + await VerifyAgainstBaselineUsingFile(compilation); + } + + [Theory] + [InlineData("sbyte")] + [InlineData("SByte")] + [InlineData("byte")] + [InlineData("Byte")] + [InlineData("short")] + [InlineData("Int16")] + [InlineData("ushort")] + [InlineData("UInt16")] + [InlineData("int")] + [InlineData("Int32")] + [InlineData("uint")] + [InlineData("UInt32")] + [InlineData("long")] + [InlineData("Int64")] + [InlineData("ulong")] + [InlineData("UInt64")] + [InlineData("float")] + [InlineData("Single")] + [InlineData("double")] + [InlineData("Double")] + [InlineData("decimal")] + [InlineData("Decimal")] + public async Task MapAction_SingleNumericParam_StringReturn(string numericType) + { + var (results, compilation) = await RunGeneratorAsync($$""" +app.MapGet("/hello", ([FromQuery]{{numericType}} p) => p.ToString()); """); var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure/Bindability.cs b/src/Shared/RoslynUtils/Bindability.cs similarity index 100% rename from src/Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure/Bindability.cs rename to src/Shared/RoslynUtils/Bindability.cs diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure/Parsability.cs b/src/Shared/RoslynUtils/Parsability.cs similarity index 100% rename from src/Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure/Parsability.cs rename to src/Shared/RoslynUtils/Parsability.cs diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure/ParsabilityHelper.cs b/src/Shared/RoslynUtils/ParsabilityHelper.cs similarity index 100% rename from src/Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure/ParsabilityHelper.cs rename to src/Shared/RoslynUtils/ParsabilityHelper.cs From 24f557452d11a456634d90203996f8f4d4b26e3d Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Wed, 22 Feb 2023 13:12:21 +1100 Subject: [PATCH 03/11] Handle TryParse method precedence and reused more of ParsabilityHelper. --- .../Microsoft.AspNetCore.App.Analyzers.csproj | 1 + ...icrosoft.AspNetCore.Http.Generators.csproj | 1 + .../gen/RequestDelegateGeneratorSources.cs | 1 + .../Emitters/EndpointParameterEmitter.cs | 2 +- .../EndpointParameter.cs | 36 +- ...Param_ComplexReturn_Snapshot.generated.txt | 27 +- ...eParam_SimpleReturn_Snapshot.generated.txt | 3 +- ...tipleInt32Param_StringReturn.generated.txt | 6 +- ...pecialTypeParam_StringReturn.generated.txt | 27 +- ...ipleStringParam_StringReturn.generated.txt | 27 +- ...aram_StringReturn_WithFilter.generated.txt | 27 +- ...omplexTypeParam_StringReturn.generated.txt | 51 +- ...leDateOnlyParam_StringReturn.generated.txt | 1625 +++++++++++++++++ ...TimeOffsetParam_StringReturn.generated.txt | 1625 +++++++++++++++++ ...leDateTimeParam_StringReturn.generated.txt | 1625 +++++++++++++++++ ...SingleEnumParam_StringReturn.generated.txt | 51 +- ...ingleInt32Param_StringReturn.generated.txt | 26 +- ...ngValueProvided_StringReturn.generated.txt | 27 +- ...ngValueProvided_StringReturn.generated.txt | 27 +- ...ngValueProvided_StringReturn.generated.txt | 27 +- ...gleNumericParam_StringReturn.generated.txt | 1625 +++++++++++++++++ ...ngleStringParam_StringReturn.generated.txt | 27 +- ...leTimeOnlyParam_StringReturn.generated.txt | 1625 +++++++++++++++++ ...tion_TryParsePrecedenceCheck.generated.txt | 1625 +++++++++++++++++ ...pAction_NoParam_StringReturn.generated.txt | 27 +- ...tion_WithParams_StringReturn.generated.txt | 27 +- .../RequestDelegateGeneratorTestBase.cs | 1 - .../RequestDelegateGeneratorTests.cs | 26 + src/Shared/RoslynUtils/ParsabilityHelper.cs | 33 +- src/Shared/RoslynUtils/ParsabilityMethod.cs | 15 + 30 files changed, 10045 insertions(+), 228 deletions(-) create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateOnlyParam_StringReturn.generated.txt create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeOffsetParam_StringReturn.generated.txt create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeParam_StringReturn.generated.txt create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNumericParam_StringReturn.generated.txt create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleTimeOnlyParam_StringReturn.generated.txt create mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TryParsePrecedenceCheck.generated.txt create mode 100644 src/Shared/RoslynUtils/ParsabilityMethod.cs 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 5da6960da26a..e68fcbf8ccac 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj @@ -29,6 +29,7 @@ + diff --git a/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.Generators.csproj b/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.Generators.csproj index ab11f1b015b1..65cab72b0842 100644 --- a/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.Generators.csproj +++ b/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.Generators.csproj @@ -26,6 +26,7 @@ + diff --git a/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs b/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs index 2f7d8116a90f..6d7f46f0699c 100644 --- a/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs +++ b/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs @@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs index 59bdf02dc2de..b656d9d3143d 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs @@ -55,7 +55,7 @@ internal static string EmitQueryOrHeaderParameterPreparation(this EndpointParame { var parsingBlock = endpointParameter.ParsingBlockEmitter($"{endpointParameter.Name}_temp", $"{endpointParameter.Name}_parsed_temp"); builder.AppendLine($$""" - {{parsingBlock}} +{{parsingBlock}} var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.Name}}_parsed_temp!; """); diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs index 898533dc2d1b..31c9f92e7a68 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs @@ -74,37 +74,33 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKnownTypes, [NotNullWhen(true)]out Func? parsingBlockEmitter) { - if (parameter.Type.SpecialType == SpecialType.System_String) + if (ParsabilityHelper.GetParsability(parameter.Type, wellKnownTypes, out var parsabilityMethod) == Parsability.NotParsable) { parsingBlockEmitter = null; return false; } - if (ParsabilityHelper.GetParsability(parameter.Type, wellKnownTypes) == Parsability.NotParsable) + Func? preferredTryParseInvocation = parsabilityMethod switch { - parsingBlockEmitter = null; - return false; - } + ParsabilityMethod.IParsable => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", + ParsabilityMethod.TryParseWithFormatProvider => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", + ParsabilityMethod.TryParse => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, out var {{outputArgument}})""", + ParsabilityMethod.Enum => (string inputArgument, string outputArgument) => $$"""Enum.TryParse<{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}>({{inputArgument}}, out var {{outputArgument}})""", + _ => null + }; - // This is the default TryParse call that we support, but subsequent statements override as appropriate. - var preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, out var {{outputArgument}})"""; - - if (parameter.Type.Implements(wellKnownTypes.Get(WellKnownType.System_IParsable_T))) + if (preferredTryParseInvocation == null) { - preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})"""; - } - - if (parameter.Type.BaseType.SpecialType == SpecialType.System_Enum) - { - preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""Enum.TryParse<{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}>({{inputArgument}}, out var {{outputArgument}})"""; + parsingBlockEmitter = null; + return false; } parsingBlockEmitter = (inputArgument, outputArgument) => $$""" - if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}}) - { - wasParamCheckFailure = true; - } - """; + if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}}) + { + wasParamCheckFailure = true; + } +"""; return true; } 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 a72de96879f1..f4ac18fd7cb1 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -301,7 +302,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -407,7 +408,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -520,7 +521,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -640,7 +641,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -767,7 +768,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -901,7 +902,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -1042,7 +1043,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1190,7 +1191,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1345,7 +1346,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1507,7 +1508,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1676,4 +1677,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} 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 03171192a27f..f935d15fd92a 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 @@ -93,6 +93,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -1755,4 +1756,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt index 5067cfb25ee2..b909618fb994 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -200,4 +200,4 @@ namespace Microsoft.AspNetCore.Http.Generated } } } -} \ No newline at end of file +} 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 ca79acae2d5e..c4cb5810abc9 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -224,7 +225,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -330,7 +331,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -443,7 +444,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -563,7 +564,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -690,7 +691,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -824,7 +825,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -965,7 +966,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1113,7 +1114,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1268,7 +1269,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1430,7 +1431,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1599,4 +1600,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} 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 bc8cf98b876b..6f5a072ebd52 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -256,7 +257,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -362,7 +363,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -475,7 +476,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -595,7 +596,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -722,7 +723,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -856,7 +857,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -997,7 +998,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1145,7 +1146,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1300,7 +1301,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1462,7 +1463,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1631,4 +1632,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} 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 0a70c96913ea..342aecfbd68c 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -222,7 +223,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -328,7 +329,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -441,7 +442,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -561,7 +562,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -688,7 +689,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -822,7 +823,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -963,7 +964,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1111,7 +1112,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1266,7 +1267,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1428,7 +1429,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1597,4 +1598,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} 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 a1ea12e615c8..961e050a7817 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Builder 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.Func handler, [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) { @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -93,7 +94,7 @@ namespace Microsoft.AspNetCore.Http.Generated }, (del, options, inferredMetadataResult) => { - var handler = (Func)del; + var handler = (Func)del; EndpointFilterDelegate? filteredInvocation = null; if (options?.EndpointBuilder?.FilterFactories.Count > 0) @@ -120,11 +121,11 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!global::TestMapActions.Todo.TryParse(p_temp, out var p_parsed_temp)) -{ - wasParamCheckFailure = true; -} - var p_local = p_parsed_temp!; + if (!global::TestMapActions.Todo.TryParse(p_temp, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; if (wasParamCheckFailure) { @@ -145,11 +146,11 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!global::TestMapActions.Todo.TryParse(p_temp, out var p_parsed_temp)) -{ - wasParamCheckFailure = true; -} - var p_local = p_parsed_temp!; + if (!global::TestMapActions.Todo.TryParse(p_temp, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; if (wasParamCheckFailure) { @@ -246,7 +247,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -352,7 +353,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -465,7 +466,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -585,7 +586,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -712,7 +713,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -846,7 +847,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -987,7 +988,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1135,7 +1136,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1290,7 +1291,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1452,7 +1453,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1621,4 +1622,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateOnlyParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateOnlyParam_StringReturn.generated.txt new file mode 100644 index 000000000000..9f7d9183ff27 --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateOnlyParam_StringReturn.generated.txt @@ -0,0 +1,1625 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + %GENERATEDCODEATTRIBUTE% + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + %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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Globalization; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = System.DateOnly, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::System.DateOnly.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = System.DateOnly, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::System.DateOnly.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeOffsetParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeOffsetParam_StringReturn.generated.txt new file mode 100644 index 000000000000..e50cfb71419d --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeOffsetParam_StringReturn.generated.txt @@ -0,0 +1,1625 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + %GENERATEDCODEATTRIBUTE% + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + %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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Globalization; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = System.DateTimeOffset, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::System.DateTimeOffset.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = System.DateTimeOffset, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::System.DateTimeOffset.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeParam_StringReturn.generated.txt new file mode 100644 index 000000000000..06b47673c6ba --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeParam_StringReturn.generated.txt @@ -0,0 +1,1625 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + %GENERATEDCODEATTRIBUTE% + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + %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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Globalization; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = System.DateTime, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::System.DateTime.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = System.DateTime, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::System.DateTime.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} 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 1f6d30494041..1a7e644a147d 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Builder 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.Func handler, [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) { @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -93,7 +94,7 @@ namespace Microsoft.AspNetCore.Http.Generated }, (del, options, inferredMetadataResult) => { - var handler = (Func)del; + var handler = (Func)del; EndpointFilterDelegate? filteredInvocation = null; if (options?.EndpointBuilder?.FilterFactories.Count > 0) @@ -120,11 +121,11 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!Enum.TryParse(p_temp, out var p_parsed_temp)) -{ - wasParamCheckFailure = true; -} - var p_local = p_parsed_temp!; + if (!Enum.TryParse(p_temp, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; if (wasParamCheckFailure) { @@ -145,11 +146,11 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!Enum.TryParse(p_temp, out var p_parsed_temp)) -{ - wasParamCheckFailure = true; -} - var p_local = p_parsed_temp!; + if (!Enum.TryParse(p_temp, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; if (wasParamCheckFailure) { @@ -246,7 +247,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -352,7 +353,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -465,7 +466,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -585,7 +586,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -712,7 +713,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -846,7 +847,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -987,7 +988,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1135,7 +1136,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1290,7 +1291,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1452,7 +1453,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1621,4 +1622,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt index fa51c806582e..9bde77c7b252 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -352,7 +352,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -465,7 +465,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -585,7 +585,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -712,7 +712,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -846,7 +846,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -987,7 +987,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1135,7 +1135,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1290,7 +1290,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1452,7 +1452,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1621,4 +1621,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} 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 e58f1406adfa..b755b15ed365 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -230,7 +231,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -336,7 +337,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -449,7 +450,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -569,7 +570,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -696,7 +697,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -830,7 +831,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -971,7 +972,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1119,7 +1120,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1274,7 +1275,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1436,7 +1437,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1605,4 +1606,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt index 58f17086af33..6aff493747fc 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -237,7 +238,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -343,7 +344,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -456,7 +457,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -576,7 +577,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -703,7 +704,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -837,7 +838,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -978,7 +979,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1126,7 +1127,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1281,7 +1282,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1443,7 +1444,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1612,4 +1613,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt index 58f17086af33..6aff493747fc 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -237,7 +238,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -343,7 +344,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -456,7 +457,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -576,7 +577,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -703,7 +704,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -837,7 +838,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -978,7 +979,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1126,7 +1127,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1281,7 +1282,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1443,7 +1444,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1612,4 +1613,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNumericParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNumericParam_StringReturn.generated.txt new file mode 100644 index 000000000000..20b45e732c76 --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNumericParam_StringReturn.generated.txt @@ -0,0 +1,1625 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + %GENERATEDCODEATTRIBUTE% + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + %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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Globalization; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = decimal, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!decimal.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = decimal, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!decimal.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_StringReturn.generated.txt index 820077539c5a..a67a23337552 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_StringReturn.generated.txt +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_StringReturn.generated.txt @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -245,7 +246,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -351,7 +352,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -464,7 +465,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -584,7 +585,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -711,7 +712,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -845,7 +846,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -986,7 +987,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1134,7 +1135,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1289,7 +1290,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1451,7 +1452,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1620,4 +1621,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleTimeOnlyParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleTimeOnlyParam_StringReturn.generated.txt new file mode 100644 index 000000000000..b1b71b101d22 --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleTimeOnlyParam_StringReturn.generated.txt @@ -0,0 +1,1625 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + %GENERATEDCODEATTRIBUTE% + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + %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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Globalization; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = System.TimeOnly, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::System.TimeOnly.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "text/plain"; + var result = handler(p_local); + return httpContext.Response.WriteAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = System.TimeOnly, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::System.TimeOnly.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TryParsePrecedenceCheck.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TryParsePrecedenceCheck.generated.txt new file mode 100644 index 000000000000..9fef561d693d --- /dev/null +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TryParsePrecedenceCheck.generated.txt @@ -0,0 +1,1625 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable + +namespace Microsoft.AspNetCore.Builder +{ + %GENERATEDCODEATTRIBUTE% + internal class SourceKey + { + public string Path { get; init; } + public int Line { get; init; } + + public SourceKey(string path, int line) + { + Path = path; + 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. + %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 }; + + 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); + } + + } +} + +namespace Microsoft.AspNetCore.Http.Generated +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Globalization; + using System.Linq; + using System.Reflection; + 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.Metadata; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.FileProviders; + using Microsoft.Extensions.Primitives; + + using MetadataPopulator = System.Func; + using RequestDelegateFactoryFunc = System.Func; + + file static class GeneratedRouteBuilderExtensionsCore + { + + private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() + { + [(@"TestMapActions.cs", 16)] = ( + (methodInfo, options) => + { + Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); + options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); + return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; + }, + (del, options, inferredMetadataResult) => + { + var handler = (Func)del; + 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); + } + + Task RequestHandler(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = TestMapActions.PrecedenceCheckTodo, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::TestMapActions.PrecedenceCheckTodo.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + return Task.CompletedTask; + } + httpContext.Response.ContentType ??= "application/json"; + var result = handler(p_local); + return httpContext.Response.WriteAsJsonAsync(result); + } + async Task RequestHandlerFiltered(HttpContext httpContext) + { + var wasParamCheckFailure = false; + // Endpoint Parameter: p (Type = TestMapActions.PrecedenceCheckTodo, IsOptional = False, Source = Query) + var p_raw = httpContext.Request.Query["p"]; + if (StringValues.IsNullOrEmpty(p_raw)) + { + wasParamCheckFailure = true; + } + var p_temp = p_raw.ToString(); + if (!global::TestMapActions.PrecedenceCheckTodo.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) + { + wasParamCheckFailure = true; + } + var p_local = p_parsed_temp!; + + if (wasParamCheckFailure) + { + httpContext.Response.StatusCode = 400; + } + var result = await filteredInvocation(new EndpointFilterInvocationContext(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); + }), + + }; + + 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); + } + + private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) + { + var routeHandlerFilters = builder.FilterFactories; + var context0 = new EndpointFilterFactoryContext + { + MethodInfo = mi, + ApplicationServices = builder.ApplicationServices, + }; + var initialFilteredInvocation = filteredInvocation; + for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) + { + var filterFactory = routeHandlerFilters[i]; + filteredInvocation = filterFactory(context0, filteredInvocation); + } + return filteredInvocation; + } + + private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) + { + if (obj is IResult r) + { + return r.ExecuteAsync(httpContext); + } + else if (obj is string s) + { + return httpContext.Response.WriteAsync(s); + } + else + { + return httpContext.Response.WriteAsJsonAsync(obj); + } + } + + private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) + { + var feature = httpContext.Features.Get(); + + if (feature?.CanHaveBody == true) + { + if (!httpContext.Request.HasJsonContentType()) + { + httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; + return (false, default); + } + try + { + var bodyValue = await httpContext.Request.ReadFromJsonAsync(); + if (!allowEmpty && bodyValue == null) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, bodyValue); + } + return (true, bodyValue); + } + catch (IOException) + { + return (false, default); + } + catch (System.Text.Json.JsonException) + { + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; + return (false, default); + } + } + return (false, default); + } + } + + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) + { + HttpContext = httpContext; + Arg0 = arg0; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + + public int Count => 1; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + + public int Count => 2; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + + public int Count => 3; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + + public int Count => 4; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + + public int Count => 5; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + + public int Count => 6; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + + public int Count => 7; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + + public int Count => 8; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + + public int Count => 9; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + %GENERATEDCODEATTRIBUTE% + file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList + { + internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + HttpContext = httpContext; + Arg0 = arg0; + Arg1 = arg1; + Arg2 = arg2; + Arg3 = arg3; + Arg4 = arg4; + Arg5 = arg5; + Arg6 = arg6; + Arg7 = arg7; + Arg8 = arg8; + Arg9 = arg9; + } + + public object? this[int index] + { + get => index switch + { + 0 => Arg0, + 1 => Arg1, + 2 => Arg2, + 3 => Arg3, + 4 => Arg4, + 5 => Arg5, + 6 => Arg6, + 7 => Arg7, + 8 => Arg8, + 9 => Arg9, + _ => new IndexOutOfRangeException() + }; + set + { + switch (index) + { + case 0: + Arg0 = (T0)(object?)value!; + break; + case 1: + Arg1 = (T1)(object?)value!; + break; + case 2: + Arg2 = (T2)(object?)value!; + break; + case 3: + Arg3 = (T3)(object?)value!; + break; + case 4: + Arg4 = (T4)(object?)value!; + break; + case 5: + Arg5 = (T5)(object?)value!; + break; + case 6: + Arg6 = (T6)(object?)value!; + break; + case 7: + Arg7 = (T7)(object?)value!; + break; + case 8: + Arg8 = (T8)(object?)value!; + break; + case 9: + Arg9 = (T9)(object?)value!; + break; + default: + break; + } + } + } + + public override HttpContext HttpContext { get; } + + public override IList Arguments => this; + + public T0 Arg0 { get; set; } + public T1 Arg1 { get; set; } + public T2 Arg2 { get; set; } + public T3 Arg3 { get; set; } + public T4 Arg4 { get; set; } + public T5 Arg5 { get; set; } + public T6 Arg6 { get; set; } + public T7 Arg7 { get; set; } + public T8 Arg8 { get; set; } + public T9 Arg9 { get; set; } + + public int Count => 10; + + public bool IsReadOnly => false; + + public bool IsFixedSize => true; + + public void Add(object? item) + { + throw new NotSupportedException(); + } + + public void Clear() + { + throw new NotSupportedException(); + } + + public bool Contains(object? item) + { + return IndexOf(item) >= 0; + } + + public void CopyTo(object?[] array, int arrayIndex) + { + for (int i = 0; i < Arguments.Count; i++) + { + array[arrayIndex++] = Arguments[i]; + } + } + + public IEnumerator GetEnumerator() + { + for (int i = 0; i < Arguments.Count; i++) + { + yield return Arguments[i]; + } + } + + public override T GetArgument(int index) + { + return index switch + { + 0 => (T)(object)Arg0!, + 1 => (T)(object)Arg1!, + 2 => (T)(object)Arg2!, + 3 => (T)(object)Arg3!, + 4 => (T)(object)Arg4!, + 5 => (T)(object)Arg5!, + 6 => (T)(object)Arg6!, + 7 => (T)(object)Arg7!, + 8 => (T)(object)Arg8!, + 9 => (T)(object)Arg9!, + _ => throw new IndexOutOfRangeException() + }; + } + + public int IndexOf(object? item) + { + return Arguments.IndexOf(item); + } + + public void Insert(int index, object? item) + { + throw new NotSupportedException(); + } + + public bool Remove(object? item) + { + throw new NotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} 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 ba7398940a93..4a41666f9501 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -93,6 +93,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -417,7 +418,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -523,7 +524,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -636,7 +637,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -756,7 +757,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -883,7 +884,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -1017,7 +1018,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -1158,7 +1159,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1306,7 +1307,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1461,7 +1462,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1623,7 +1624,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1792,4 +1793,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} 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 73f250e2ea36..3d2033c6d838 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 @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Builder { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal class SourceKey { public string Path { get; init; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Builder // 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. - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% internal static class GenerateRouteBuilderEndpoints { private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get }; @@ -93,6 +93,7 @@ namespace Microsoft.AspNetCore.Http.Generated using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; + using System.Globalization; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -364,7 +365,7 @@ namespace Microsoft.AspNetCore.Http.Generated } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) @@ -470,7 +471,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) @@ -583,7 +584,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) @@ -703,7 +704,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) @@ -830,7 +831,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) @@ -964,7 +965,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -1105,7 +1106,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) @@ -1253,7 +1254,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) @@ -1408,7 +1409,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) @@ -1570,7 +1571,7 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.Generators, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")] + %GENERATEDCODEATTRIBUTE% file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList { internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) @@ -1739,4 +1740,4 @@ namespace Microsoft.AspNetCore.Http.Generated return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs index 176427059129..b9a57c00683c 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs @@ -248,7 +248,6 @@ internal async Task VerifyAgainstBaselineUsingFile(Compilation compilation, [Cal var baselineFilePath = Path.Combine("RequestDelegateGenerator", "Baselines", $"{callerName}.generated.txt"); var generatedSyntaxTree = compilation.SyntaxTrees.Last(); var generatedCode = await generatedSyntaxTree.GetTextAsync(); - await File.WriteAllTextAsync(baselineFilePath, generatedCode.ToString()); var baseline = await File.ReadAllTextAsync(baselineFilePath); var expectedLines = baseline .TrimEnd() // Trim newlines added by autoformat diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs index 8addd21eb318..98d5aa93cdec 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs @@ -233,6 +233,32 @@ public async Task MapAction_SingleNumericParam_StringReturn(string numericType) await VerifyAgainstBaselineUsingFile(compilation); } + [Theory] + [InlineData("PrecedenceCheckTodoWithoutFormat", "24")] + [InlineData("PrecedenceCheckTodo", "42")] + public async Task MapAction_TryParsePrecedenceCheck(string parameterType, string result) + { + var (results, compilation) = await RunGeneratorAsync($$""" +app.MapGet("/hello", ([FromQuery]{{parameterType}} p) => p.MagicValue); +"""); + + var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); + var endpoint = GetEndpointFromCompilation(compilation); + + Assert.Equal("/hello", endpointModel.RoutePattern); + Assert.Equal("MapGet", endpointModel.HttpMethod); + var p = Assert.Single(endpointModel.Parameters); + Assert.Equal(EndpointParameterSource.Query, p.Source); + Assert.Equal("p", p.Name); + + var httpContext = CreateHttpContext(); + httpContext.Request.QueryString = new QueryString("?p=1"); + + await endpoint.RequestDelegate(httpContext); + await VerifyResponseBodyAsync(httpContext, result); + await VerifyAgainstBaselineUsingFile(compilation); + } + [Fact] public async Task MapAction_SingleComplexTypeParam_StringReturn() { diff --git a/src/Shared/RoslynUtils/ParsabilityHelper.cs b/src/Shared/RoslynUtils/ParsabilityHelper.cs index 124832884c96..f3cd60ffec4c 100644 --- a/src/Shared/RoslynUtils/ParsabilityHelper.cs +++ b/src/Shared/RoslynUtils/ParsabilityHelper.cs @@ -16,32 +16,41 @@ namespace Microsoft.AspNetCore.Analyzers.Infrastructure; internal static class ParsabilityHelper { - private static bool IsTypeAlwaysParsableOrBindable(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes) + private static bool IsTypeAlwaysParsableOrBindable(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes, out ParsabilityMethod? parsabilityMethod) { // Any enum is valid. if (typeSymbol.TypeKind == TypeKind.Enum) { + parsabilityMethod = ParsabilityMethod.Enum; return true; } // Uri is valid. if (SymbolEqualityComparer.Default.Equals(typeSymbol, wellKnownTypes.Get(WellKnownType.System_Uri))) { + parsabilityMethod = ParsabilityMethod.Uri; return true; } // Strings are valid. if (typeSymbol.SpecialType == SpecialType.System_String) { + parsabilityMethod = ParsabilityMethod.String; return true; } + parsabilityMethod = null; return false; } internal static Parsability GetParsability(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes) { - if (IsTypeAlwaysParsableOrBindable(typeSymbol, wellKnownTypes)) + return GetParsability(typeSymbol, wellKnownTypes, out var _); + } + + internal static Parsability GetParsability(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes, out ParsabilityMethod? parsabilityMethod) + { + if (IsTypeAlwaysParsableOrBindable(typeSymbol, wellKnownTypes, out parsabilityMethod)) { return Parsability.Parsable; } @@ -49,17 +58,23 @@ internal static Parsability GetParsability(ITypeSymbol typeSymbol, WellKnownType // MyType : IParsable() if (IsParsableViaIParsable(typeSymbol, wellKnownTypes)) { + parsabilityMethod = ParsabilityMethod.IParsable; return Parsability.Parsable; } // Check if the parameter type has a public static TryParse method. var tryParseMethods = typeSymbol.GetMembers("TryParse").OfType(); - foreach (var tryParseMethodSymbol in tryParseMethods) + + if (tryParseMethods.Any(m => IsTryParseWithFormat(m, wellKnownTypes))) { - if (IsTryParse(tryParseMethodSymbol) || IsTryParseWithFormat(tryParseMethodSymbol, wellKnownTypes)) - { - return Parsability.Parsable; - } + parsabilityMethod = ParsabilityMethod.TryParseWithFormatProvider; + return Parsability.Parsable; + } + + if (tryParseMethods.Any(m => IsTryParse(m))) + { + parsabilityMethod = ParsabilityMethod.TryParse; + return Parsability.Parsable; } return Parsability.NotParsable; @@ -86,7 +101,7 @@ private static bool IsTryParseWithFormat(IMethodSymbol methodSymbol, WellKnownTy methodSymbol.Parameters[2].RefKind == RefKind.Out; } - private static bool IsParsableViaIParsable(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes) + internal static bool IsParsableViaIParsable(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes) { var iParsableTypeSymbol = wellKnownTypes.Get(WellKnownType.System_IParsable_T); var implementsIParsable = typeSymbol.AllInterfaces.Any( @@ -134,7 +149,7 @@ private static bool IsReturningValueTaskOfT(INamedTypeSymbol returnType, INamedT internal static Bindability GetBindability(INamedTypeSymbol typeSymbol, WellKnownTypes wellKnownTypes) { - if (IsTypeAlwaysParsableOrBindable(typeSymbol, wellKnownTypes)) + if (IsTypeAlwaysParsableOrBindable(typeSymbol, wellKnownTypes, out var _)) { return Bindability.Bindable; } diff --git a/src/Shared/RoslynUtils/ParsabilityMethod.cs b/src/Shared/RoslynUtils/ParsabilityMethod.cs new file mode 100644 index 000000000000..216df132f9f2 --- /dev/null +++ b/src/Shared/RoslynUtils/ParsabilityMethod.cs @@ -0,0 +1,15 @@ +// 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.Analyzers.Infrastructure; + +internal enum ParsabilityMethod +{ + NotParsable, + String, + IParsable, + Enum, + TryParse, + TryParseWithFormatProvider, + Uri +} From c840b0417893b86777ebefe6e14a9d314793c45d Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Wed, 22 Feb 2023 13:39:09 +1100 Subject: [PATCH 04/11] Remove unnecessary lambda. --- src/Shared/RoslynUtils/ParsabilityHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shared/RoslynUtils/ParsabilityHelper.cs b/src/Shared/RoslynUtils/ParsabilityHelper.cs index f3cd60ffec4c..7ed05a719eb1 100644 --- a/src/Shared/RoslynUtils/ParsabilityHelper.cs +++ b/src/Shared/RoslynUtils/ParsabilityHelper.cs @@ -71,7 +71,7 @@ internal static Parsability GetParsability(ITypeSymbol typeSymbol, WellKnownType return Parsability.Parsable; } - if (tryParseMethods.Any(m => IsTryParse(m))) + if (tryParseMethods.Any(IsTryParse)) { parsabilityMethod = ParsabilityMethod.TryParse; return Parsability.Parsable; From 5e8617dcdd7cb0f085570ecc9ec2376516e3ff36 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Wed, 22 Feb 2023 14:50:35 +1100 Subject: [PATCH 05/11] PR feedback from Safia. --- .../Emitters/EndpointParameterEmitter.cs | 9 + .../EndpointParameter.cs | 13 +- ...tipleInt32Param_StringReturn.generated.txt | 203 -- ...leDateOnlyParam_StringReturn.generated.txt | 1625 ----------------- ...TimeOffsetParam_StringReturn.generated.txt | 1625 ----------------- ...leDateTimeParam_StringReturn.generated.txt | 1625 ----------------- ...ingleInt32Param_StringReturn.generated.txt | 1624 ---------------- ...gleNumericParam_StringReturn.generated.txt | 1625 ----------------- ...tion_TryParsePrecedenceCheck.generated.txt | 1625 ----------------- .../RequestDelegateGeneratorTests.cs | 64 +- 10 files changed, 30 insertions(+), 10008 deletions(-) delete mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt delete mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateOnlyParam_StringReturn.generated.txt delete mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeOffsetParam_StringReturn.generated.txt delete mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeParam_StringReturn.generated.txt delete mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt delete mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNumericParam_StringReturn.generated.txt delete mode 100644 src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TryParsePrecedenceCheck.generated.txt diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs index b656d9d3143d..43fe9f0faaad 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs @@ -51,6 +51,15 @@ internal static string EmitQueryOrHeaderParameterPreparation(this EndpointParame """); } + builder.Append(endpointParameter.EmitParsingBlock()); + + return builder.ToString(); + } + + internal static string EmitParsingBlock(this EndpointParameter endpointParameter) + { + var builder = new StringBuilder(); + if (endpointParameter.IsParsable) { var parsingBlock = endpointParameter.ParsingBlockEmitter($"{endpointParameter.Name}_temp", $"{endpointParameter.Name}_parsed_temp"); diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs index 31c9f92e7a68..c04730fb53ba 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs @@ -74,27 +74,37 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKnownTypes, [NotNullWhen(true)]out Func? parsingBlockEmitter) { + // ParsabilityHelper returns a single enumeration with a Parsable/NonParsable enumeration result. We use this already + // in the analyzers to determine whether we need to warn on whether a type needs to implement TryParse/IParsable. To + // support usage in the code generator an optiona out parameter has been added to hint at what variant of the various + // TryParse methods should be used (this implies that the preferences are baked into ParsabilityHelper). If we aren't + // parsable at all we bail. if (ParsabilityHelper.GetParsability(parameter.Type, wellKnownTypes, out var parsabilityMethod) == Parsability.NotParsable) { parsingBlockEmitter = null; return false; } + // If we are parsable we need to emit code based on the enumeration ParsabilityMethod which has a bunch of members + // which spell out the preferred TryParse uage. This swtich statement makes slight variations to them based on + // which method was encountered. Func? preferredTryParseInvocation = parsabilityMethod switch { ParsabilityMethod.IParsable => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", ParsabilityMethod.TryParseWithFormatProvider => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", ParsabilityMethod.TryParse => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, out var {{outputArgument}})""", ParsabilityMethod.Enum => (string inputArgument, string outputArgument) => $$"""Enum.TryParse<{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}>({{inputArgument}}, out var {{outputArgument}})""", - _ => null + _ => null // ... everything that is parsable is covered above except strings ... }; + // ... so for strings (null) we bail. if (preferredTryParseInvocation == null) { parsingBlockEmitter = null; return false; } + // Wrap the TryParse method call in an if-block and if it doesn't work set param check failure. parsingBlockEmitter = (inputArgument, outputArgument) => $$""" if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}}) { @@ -112,6 +122,7 @@ private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes internal string? AssigningCode { get; set; } public string Name { get; } public bool IsOptional { get; } + [MemberNotNull("ParsingBlockEmitter")] public bool IsParsable { get; } public Func ParsingBlockEmitter { get; } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt deleted file mode 100644 index b909618fb994..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_MultipleInt32Param_StringReturn.generated.txt +++ /dev/null @@ -1,203 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#nullable enable - -namespace Microsoft.AspNetCore.Builder -{ - %GENERATEDCODEATTRIBUTE% - internal class SourceKey - { - public string Path { get; init; } - public int Line { get; init; } - - public SourceKey(string path, int line) - { - Path = path; - 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. - %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 }; - - 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); - } - - } -} - -namespace Microsoft.AspNetCore.Http.Generated -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Linq; - using System.Reflection; - 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.Metadata; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.FileProviders; - using Microsoft.Extensions.Primitives; - - using MetadataPopulator = System.Func; - using RequestDelegateFactoryFunc = System.Func; - - file static class GeneratedRouteBuilderExtensionsCore - { - - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { - [(@"TestMapActions.cs", 15)] = ( - (methodInfo, options) => - { - Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 15)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - var handler = (System.Func)del; - 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); - } - - Task RequestHandler(HttpContext httpContext) - { - // Endpoint Parameter: p1 (Type = int, IsOptional = False, Source = Query) - var p1_raw = httpContext.Request.Query["p1"]; - if (StringValues.IsNullOrEmpty(p1_raw)) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - if (!int.TryParse(p1_raw, out var p1_local)) -{ - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; -} - - // Endpoint Parameter: p2 (Type = int, IsOptional = False, Source = Query) - var p2_raw = httpContext.Request.Query["p2"]; - if (StringValues.IsNullOrEmpty(p2_raw)) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - if (!int.TryParse(p2_raw, out var p2_local)) -{ - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; -} - - httpContext.Response.ContentType ??= "text/plain"; - var result = handler(p1_local, p2_local); - return httpContext.Response.WriteAsync(result); - } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var result = await filteredInvocation(new DefaultEndpointFilterInvocationContext(httpContext)); - await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext); - } - - 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) - { - var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)]; - return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate); - } - - private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) - { - var routeHandlerFilters = builder.FilterFactories; - var context0 = new EndpointFilterFactoryContext - { - MethodInfo = mi, - ApplicationServices = builder.ApplicationServices, - }; - var initialFilteredInvocation = filteredInvocation; - for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) - { - var filterFactory = routeHandlerFilters[i]; - filteredInvocation = filterFactory(context0, filteredInvocation); - } - return filteredInvocation; - } - - private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) - { - if (obj is IResult r) - { - return r.ExecuteAsync(httpContext); - } - else if (obj is string s) - { - return httpContext.Response.WriteAsync(s); - } - else - { - return httpContext.Response.WriteAsJsonAsync(obj); - } - } - } -} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateOnlyParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateOnlyParam_StringReturn.generated.txt deleted file mode 100644 index 9f7d9183ff27..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateOnlyParam_StringReturn.generated.txt +++ /dev/null @@ -1,1625 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#nullable enable - -namespace Microsoft.AspNetCore.Builder -{ - %GENERATEDCODEATTRIBUTE% - internal class SourceKey - { - public string Path { get; init; } - public int Line { get; init; } - - public SourceKey(string path, int line) - { - Path = path; - 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. - %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 }; - - 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); - } - - } -} - -namespace Microsoft.AspNetCore.Http.Generated -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Globalization; - using System.Linq; - using System.Reflection; - 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.Metadata; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.FileProviders; - using Microsoft.Extensions.Primitives; - - using MetadataPopulator = System.Func; - using RequestDelegateFactoryFunc = System.Func; - - file static class GeneratedRouteBuilderExtensionsCore - { - - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { - [(@"TestMapActions.cs", 16)] = ( - (methodInfo, options) => - { - Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - var handler = (Func)del; - 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); - } - - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = System.DateOnly, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!global::System.DateOnly.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - httpContext.Response.ContentType ??= "text/plain"; - var result = handler(p_local); - return httpContext.Response.WriteAsync(result); - } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = System.DateOnly, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!global::System.DateOnly.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(new EndpointFilterInvocationContext(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); - }), - - }; - - 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); - } - - private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) - { - var routeHandlerFilters = builder.FilterFactories; - var context0 = new EndpointFilterFactoryContext - { - MethodInfo = mi, - ApplicationServices = builder.ApplicationServices, - }; - var initialFilteredInvocation = filteredInvocation; - for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) - { - var filterFactory = routeHandlerFilters[i]; - filteredInvocation = filterFactory(context0, filteredInvocation); - } - return filteredInvocation; - } - - private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) - { - if (obj is IResult r) - { - return r.ExecuteAsync(httpContext); - } - else if (obj is string s) - { - return httpContext.Response.WriteAsync(s); - } - else - { - return httpContext.Response.WriteAsJsonAsync(obj); - } - } - - private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) - { - var feature = httpContext.Features.Get(); - - if (feature?.CanHaveBody == true) - { - if (!httpContext.Request.HasJsonContentType()) - { - httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; - return (false, default); - } - try - { - var bodyValue = await httpContext.Request.ReadFromJsonAsync(); - if (!allowEmpty && bodyValue == null) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, bodyValue); - } - return (true, bodyValue); - } - catch (IOException) - { - return (false, default); - } - catch (System.Text.Json.JsonException) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, default); - } - } - return (false, default); - } - } - - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) - { - HttpContext = httpContext; - Arg0 = arg0; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - - public int Count => 1; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - - public int Count => 2; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - - public int Count => 3; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - - public int Count => 4; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - - public int Count => 5; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - - public int Count => 6; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - - public int Count => 7; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - - public int Count => 8; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - - public int Count => 9; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - Arg9 = arg9; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - 9 => Arg9, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - case 9: - Arg9 = (T9)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - public T9 Arg9 { get; set; } - - public int Count => 10; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - 9 => (T)(object)Arg9!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeOffsetParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeOffsetParam_StringReturn.generated.txt deleted file mode 100644 index e50cfb71419d..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeOffsetParam_StringReturn.generated.txt +++ /dev/null @@ -1,1625 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#nullable enable - -namespace Microsoft.AspNetCore.Builder -{ - %GENERATEDCODEATTRIBUTE% - internal class SourceKey - { - public string Path { get; init; } - public int Line { get; init; } - - public SourceKey(string path, int line) - { - Path = path; - 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. - %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 }; - - 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); - } - - } -} - -namespace Microsoft.AspNetCore.Http.Generated -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Globalization; - using System.Linq; - using System.Reflection; - 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.Metadata; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.FileProviders; - using Microsoft.Extensions.Primitives; - - using MetadataPopulator = System.Func; - using RequestDelegateFactoryFunc = System.Func; - - file static class GeneratedRouteBuilderExtensionsCore - { - - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { - [(@"TestMapActions.cs", 16)] = ( - (methodInfo, options) => - { - Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - var handler = (Func)del; - 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); - } - - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = System.DateTimeOffset, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!global::System.DateTimeOffset.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - httpContext.Response.ContentType ??= "text/plain"; - var result = handler(p_local); - return httpContext.Response.WriteAsync(result); - } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = System.DateTimeOffset, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!global::System.DateTimeOffset.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(new EndpointFilterInvocationContext(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); - }), - - }; - - 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); - } - - private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) - { - var routeHandlerFilters = builder.FilterFactories; - var context0 = new EndpointFilterFactoryContext - { - MethodInfo = mi, - ApplicationServices = builder.ApplicationServices, - }; - var initialFilteredInvocation = filteredInvocation; - for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) - { - var filterFactory = routeHandlerFilters[i]; - filteredInvocation = filterFactory(context0, filteredInvocation); - } - return filteredInvocation; - } - - private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) - { - if (obj is IResult r) - { - return r.ExecuteAsync(httpContext); - } - else if (obj is string s) - { - return httpContext.Response.WriteAsync(s); - } - else - { - return httpContext.Response.WriteAsJsonAsync(obj); - } - } - - private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) - { - var feature = httpContext.Features.Get(); - - if (feature?.CanHaveBody == true) - { - if (!httpContext.Request.HasJsonContentType()) - { - httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; - return (false, default); - } - try - { - var bodyValue = await httpContext.Request.ReadFromJsonAsync(); - if (!allowEmpty && bodyValue == null) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, bodyValue); - } - return (true, bodyValue); - } - catch (IOException) - { - return (false, default); - } - catch (System.Text.Json.JsonException) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, default); - } - } - return (false, default); - } - } - - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) - { - HttpContext = httpContext; - Arg0 = arg0; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - - public int Count => 1; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - - public int Count => 2; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - - public int Count => 3; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - - public int Count => 4; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - - public int Count => 5; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - - public int Count => 6; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - - public int Count => 7; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - - public int Count => 8; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - - public int Count => 9; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - Arg9 = arg9; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - 9 => Arg9, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - case 9: - Arg9 = (T9)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - public T9 Arg9 { get; set; } - - public int Count => 10; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - 9 => (T)(object)Arg9!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeParam_StringReturn.generated.txt deleted file mode 100644 index 06b47673c6ba..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleDateTimeParam_StringReturn.generated.txt +++ /dev/null @@ -1,1625 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#nullable enable - -namespace Microsoft.AspNetCore.Builder -{ - %GENERATEDCODEATTRIBUTE% - internal class SourceKey - { - public string Path { get; init; } - public int Line { get; init; } - - public SourceKey(string path, int line) - { - Path = path; - 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. - %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 }; - - 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); - } - - } -} - -namespace Microsoft.AspNetCore.Http.Generated -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Globalization; - using System.Linq; - using System.Reflection; - 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.Metadata; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.FileProviders; - using Microsoft.Extensions.Primitives; - - using MetadataPopulator = System.Func; - using RequestDelegateFactoryFunc = System.Func; - - file static class GeneratedRouteBuilderExtensionsCore - { - - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { - [(@"TestMapActions.cs", 16)] = ( - (methodInfo, options) => - { - Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - var handler = (Func)del; - 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); - } - - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = System.DateTime, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!global::System.DateTime.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - httpContext.Response.ContentType ??= "text/plain"; - var result = handler(p_local); - return httpContext.Response.WriteAsync(result); - } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = System.DateTime, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!global::System.DateTime.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(new EndpointFilterInvocationContext(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); - }), - - }; - - 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); - } - - private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) - { - var routeHandlerFilters = builder.FilterFactories; - var context0 = new EndpointFilterFactoryContext - { - MethodInfo = mi, - ApplicationServices = builder.ApplicationServices, - }; - var initialFilteredInvocation = filteredInvocation; - for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) - { - var filterFactory = routeHandlerFilters[i]; - filteredInvocation = filterFactory(context0, filteredInvocation); - } - return filteredInvocation; - } - - private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) - { - if (obj is IResult r) - { - return r.ExecuteAsync(httpContext); - } - else if (obj is string s) - { - return httpContext.Response.WriteAsync(s); - } - else - { - return httpContext.Response.WriteAsJsonAsync(obj); - } - } - - private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) - { - var feature = httpContext.Features.Get(); - - if (feature?.CanHaveBody == true) - { - if (!httpContext.Request.HasJsonContentType()) - { - httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; - return (false, default); - } - try - { - var bodyValue = await httpContext.Request.ReadFromJsonAsync(); - if (!allowEmpty && bodyValue == null) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, bodyValue); - } - return (true, bodyValue); - } - catch (IOException) - { - return (false, default); - } - catch (System.Text.Json.JsonException) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, default); - } - } - return (false, default); - } - } - - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) - { - HttpContext = httpContext; - Arg0 = arg0; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - - public int Count => 1; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - - public int Count => 2; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - - public int Count => 3; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - - public int Count => 4; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - - public int Count => 5; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - - public int Count => 6; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - - public int Count => 7; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - - public int Count => 8; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - - public int Count => 9; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - Arg9 = arg9; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - 9 => Arg9, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - case 9: - Arg9 = (T9)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - public T9 Arg9 { get; set; } - - public int Count => 10; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - 9 => (T)(object)Arg9!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt deleted file mode 100644 index 9bde77c7b252..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleInt32Param_StringReturn.generated.txt +++ /dev/null @@ -1,1624 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#nullable enable - -namespace Microsoft.AspNetCore.Builder -{ - %GENERATEDCODEATTRIBUTE% - internal class SourceKey - { - public string Path { get; init; } - public int Line { get; init; } - - public SourceKey(string path, int line) - { - Path = path; - 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. - %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 }; - - 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); - } - - } -} - -namespace Microsoft.AspNetCore.Http.Generated -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Linq; - using System.Reflection; - 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.Metadata; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.FileProviders; - using Microsoft.Extensions.Primitives; - - using MetadataPopulator = System.Func; - using RequestDelegateFactoryFunc = System.Func; - - file static class GeneratedRouteBuilderExtensionsCore - { - - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { - [(@"TestMapActions.cs", 16)] = ( - (methodInfo, options) => - { - Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - var handler = (Func)del; - 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); - } - - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = int, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!int.TryParse(p_temp, out var p_parsed_temp)) -{ - wasParamCheckFailure = true; -} - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - httpContext.Response.ContentType ??= "text/plain"; - var result = handler(p_local); - return httpContext.Response.WriteAsync(result); - } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = int, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!int.TryParse(p_temp, out var p_parsed_temp)) -{ - wasParamCheckFailure = true; -} - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(new EndpointFilterInvocationContext(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); - }), - - }; - - 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); - } - - private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) - { - var routeHandlerFilters = builder.FilterFactories; - var context0 = new EndpointFilterFactoryContext - { - MethodInfo = mi, - ApplicationServices = builder.ApplicationServices, - }; - var initialFilteredInvocation = filteredInvocation; - for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) - { - var filterFactory = routeHandlerFilters[i]; - filteredInvocation = filterFactory(context0, filteredInvocation); - } - return filteredInvocation; - } - - private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) - { - if (obj is IResult r) - { - return r.ExecuteAsync(httpContext); - } - else if (obj is string s) - { - return httpContext.Response.WriteAsync(s); - } - else - { - return httpContext.Response.WriteAsJsonAsync(obj); - } - } - - private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) - { - var feature = httpContext.Features.Get(); - - if (feature?.CanHaveBody == true) - { - if (!httpContext.Request.HasJsonContentType()) - { - httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; - return (false, default); - } - try - { - var bodyValue = await httpContext.Request.ReadFromJsonAsync(); - if (!allowEmpty && bodyValue == null) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, bodyValue); - } - return (true, bodyValue); - } - catch (IOException) - { - return (false, default); - } - catch (System.Text.Json.JsonException) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, default); - } - } - return (false, default); - } - } - - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) - { - HttpContext = httpContext; - Arg0 = arg0; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - - public int Count => 1; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - - public int Count => 2; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - - public int Count => 3; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - - public int Count => 4; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - - public int Count => 5; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - - public int Count => 6; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - - public int Count => 7; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - - public int Count => 8; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - - public int Count => 9; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - Arg9 = arg9; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - 9 => Arg9, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - case 9: - Arg9 = (T9)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - public T9 Arg9 { get; set; } - - public int Count => 10; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - 9 => (T)(object)Arg9!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNumericParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNumericParam_StringReturn.generated.txt deleted file mode 100644 index 20b45e732c76..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNumericParam_StringReturn.generated.txt +++ /dev/null @@ -1,1625 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#nullable enable - -namespace Microsoft.AspNetCore.Builder -{ - %GENERATEDCODEATTRIBUTE% - internal class SourceKey - { - public string Path { get; init; } - public int Line { get; init; } - - public SourceKey(string path, int line) - { - Path = path; - 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. - %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 }; - - 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); - } - - } -} - -namespace Microsoft.AspNetCore.Http.Generated -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Globalization; - using System.Linq; - using System.Reflection; - 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.Metadata; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.FileProviders; - using Microsoft.Extensions.Primitives; - - using MetadataPopulator = System.Func; - using RequestDelegateFactoryFunc = System.Func; - - file static class GeneratedRouteBuilderExtensionsCore - { - - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { - [(@"TestMapActions.cs", 16)] = ( - (methodInfo, options) => - { - Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - var handler = (Func)del; - 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); - } - - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = decimal, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!decimal.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - httpContext.Response.ContentType ??= "text/plain"; - var result = handler(p_local); - return httpContext.Response.WriteAsync(result); - } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = decimal, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!decimal.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(new EndpointFilterInvocationContext(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); - }), - - }; - - 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); - } - - private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) - { - var routeHandlerFilters = builder.FilterFactories; - var context0 = new EndpointFilterFactoryContext - { - MethodInfo = mi, - ApplicationServices = builder.ApplicationServices, - }; - var initialFilteredInvocation = filteredInvocation; - for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) - { - var filterFactory = routeHandlerFilters[i]; - filteredInvocation = filterFactory(context0, filteredInvocation); - } - return filteredInvocation; - } - - private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) - { - if (obj is IResult r) - { - return r.ExecuteAsync(httpContext); - } - else if (obj is string s) - { - return httpContext.Response.WriteAsync(s); - } - else - { - return httpContext.Response.WriteAsJsonAsync(obj); - } - } - - private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) - { - var feature = httpContext.Features.Get(); - - if (feature?.CanHaveBody == true) - { - if (!httpContext.Request.HasJsonContentType()) - { - httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; - return (false, default); - } - try - { - var bodyValue = await httpContext.Request.ReadFromJsonAsync(); - if (!allowEmpty && bodyValue == null) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, bodyValue); - } - return (true, bodyValue); - } - catch (IOException) - { - return (false, default); - } - catch (System.Text.Json.JsonException) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, default); - } - } - return (false, default); - } - } - - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) - { - HttpContext = httpContext; - Arg0 = arg0; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - - public int Count => 1; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - - public int Count => 2; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - - public int Count => 3; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - - public int Count => 4; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - - public int Count => 5; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - - public int Count => 6; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - - public int Count => 7; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - - public int Count => 8; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - - public int Count => 9; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - Arg9 = arg9; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - 9 => Arg9, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - case 9: - Arg9 = (T9)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - public T9 Arg9 { get; set; } - - public int Count => 10; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - 9 => (T)(object)Arg9!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TryParsePrecedenceCheck.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TryParsePrecedenceCheck.generated.txt deleted file mode 100644 index 9fef561d693d..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_TryParsePrecedenceCheck.generated.txt +++ /dev/null @@ -1,1625 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#nullable enable - -namespace Microsoft.AspNetCore.Builder -{ - %GENERATEDCODEATTRIBUTE% - internal class SourceKey - { - public string Path { get; init; } - public int Line { get; init; } - - public SourceKey(string path, int line) - { - Path = path; - 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. - %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 }; - - 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); - } - - } -} - -namespace Microsoft.AspNetCore.Http.Generated -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Globalization; - using System.Linq; - using System.Reflection; - 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.Metadata; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.FileProviders; - using Microsoft.Extensions.Primitives; - - using MetadataPopulator = System.Func; - using RequestDelegateFactoryFunc = System.Func; - - file static class GeneratedRouteBuilderExtensionsCore - { - - private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new() - { - [(@"TestMapActions.cs", 16)] = ( - (methodInfo, options) => - { - Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found."); - options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 16)); - return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() }; - }, - (del, options, inferredMetadataResult) => - { - var handler = (Func)del; - 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); - } - - Task RequestHandler(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = TestMapActions.PrecedenceCheckTodo, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!global::TestMapActions.PrecedenceCheckTodo.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - return Task.CompletedTask; - } - httpContext.Response.ContentType ??= "application/json"; - var result = handler(p_local); - return httpContext.Response.WriteAsJsonAsync(result); - } - async Task RequestHandlerFiltered(HttpContext httpContext) - { - var wasParamCheckFailure = false; - // Endpoint Parameter: p (Type = TestMapActions.PrecedenceCheckTodo, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - if (!global::TestMapActions.PrecedenceCheckTodo.TryParse(p_temp, CultureInfo.InvariantCulture, out var p_parsed_temp)) - { - wasParamCheckFailure = true; - } - var p_local = p_parsed_temp!; - - if (wasParamCheckFailure) - { - httpContext.Response.StatusCode = 400; - } - var result = await filteredInvocation(new EndpointFilterInvocationContext(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); - }), - - }; - - 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); - } - - private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi) - { - var routeHandlerFilters = builder.FilterFactories; - var context0 = new EndpointFilterFactoryContext - { - MethodInfo = mi, - ApplicationServices = builder.ApplicationServices, - }; - var initialFilteredInvocation = filteredInvocation; - for (var i = routeHandlerFilters.Count - 1; i >= 0; i--) - { - var filterFactory = routeHandlerFilters[i]; - filteredInvocation = filterFactory(context0, filteredInvocation); - } - return filteredInvocation; - } - - private static Task ExecuteObjectResult(object? obj, HttpContext httpContext) - { - if (obj is IResult r) - { - return r.ExecuteAsync(httpContext); - } - else if (obj is string s) - { - return httpContext.Response.WriteAsync(s); - } - else - { - return httpContext.Response.WriteAsJsonAsync(obj); - } - } - - private static async ValueTask<(bool, T?)> TryResolveBody(HttpContext httpContext, bool allowEmpty) - { - var feature = httpContext.Features.Get(); - - if (feature?.CanHaveBody == true) - { - if (!httpContext.Request.HasJsonContentType()) - { - httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; - return (false, default); - } - try - { - var bodyValue = await httpContext.Request.ReadFromJsonAsync(); - if (!allowEmpty && bodyValue == null) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, bodyValue); - } - return (true, bodyValue); - } - catch (IOException) - { - return (false, default); - } - catch (System.Text.Json.JsonException) - { - httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; - return (false, default); - } - } - return (false, default); - } - } - - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0) - { - HttpContext = httpContext; - Arg0 = arg0; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - - public int Count => 1; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - - public int Count => 2; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - - public int Count => 3; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - - public int Count => 4; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - - public int Count => 5; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - - public int Count => 6; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - - public int Count => 7; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - - public int Count => 8; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - - public int Count => 9; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - %GENERATEDCODEATTRIBUTE% - file class EndpointFilterInvocationContext : EndpointFilterInvocationContext, IList - { - internal EndpointFilterInvocationContext(HttpContext httpContext, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - HttpContext = httpContext; - Arg0 = arg0; - Arg1 = arg1; - Arg2 = arg2; - Arg3 = arg3; - Arg4 = arg4; - Arg5 = arg5; - Arg6 = arg6; - Arg7 = arg7; - Arg8 = arg8; - Arg9 = arg9; - } - - public object? this[int index] - { - get => index switch - { - 0 => Arg0, - 1 => Arg1, - 2 => Arg2, - 3 => Arg3, - 4 => Arg4, - 5 => Arg5, - 6 => Arg6, - 7 => Arg7, - 8 => Arg8, - 9 => Arg9, - _ => new IndexOutOfRangeException() - }; - set - { - switch (index) - { - case 0: - Arg0 = (T0)(object?)value!; - break; - case 1: - Arg1 = (T1)(object?)value!; - break; - case 2: - Arg2 = (T2)(object?)value!; - break; - case 3: - Arg3 = (T3)(object?)value!; - break; - case 4: - Arg4 = (T4)(object?)value!; - break; - case 5: - Arg5 = (T5)(object?)value!; - break; - case 6: - Arg6 = (T6)(object?)value!; - break; - case 7: - Arg7 = (T7)(object?)value!; - break; - case 8: - Arg8 = (T8)(object?)value!; - break; - case 9: - Arg9 = (T9)(object?)value!; - break; - default: - break; - } - } - } - - public override HttpContext HttpContext { get; } - - public override IList Arguments => this; - - public T0 Arg0 { get; set; } - public T1 Arg1 { get; set; } - public T2 Arg2 { get; set; } - public T3 Arg3 { get; set; } - public T4 Arg4 { get; set; } - public T5 Arg5 { get; set; } - public T6 Arg6 { get; set; } - public T7 Arg7 { get; set; } - public T8 Arg8 { get; set; } - public T9 Arg9 { get; set; } - - public int Count => 10; - - public bool IsReadOnly => false; - - public bool IsFixedSize => true; - - public void Add(object? item) - { - throw new NotSupportedException(); - } - - public void Clear() - { - throw new NotSupportedException(); - } - - public bool Contains(object? item) - { - return IndexOf(item) >= 0; - } - - public void CopyTo(object?[] array, int arrayIndex) - { - for (int i = 0; i < Arguments.Count; i++) - { - array[arrayIndex++] = Arguments[i]; - } - } - - public IEnumerator GetEnumerator() - { - for (int i = 0; i < Arguments.Count; i++) - { - yield return Arguments[i]; - } - } - - public override T GetArgument(int index) - { - return index switch - { - 0 => (T)(object)Arg0!, - 1 => (T)(object)Arg1!, - 2 => (T)(object)Arg2!, - 3 => (T)(object)Arg3!, - 4 => (T)(object)Arg4!, - 5 => (T)(object)Arg5!, - 6 => (T)(object)Arg6!, - 7 => (T)(object)Arg7!, - 8 => (T)(object)Arg8!, - 9 => (T)(object)Arg9!, - _ => throw new IndexOutOfRangeException() - }; - } - - public int IndexOf(object? item) - { - return Arguments.IndexOf(item); - } - - public void Insert(int index, object? item) - { - throw new NotSupportedException(); - } - - public bool Remove(object? item) - { - throw new NotSupportedException(); - } - - public void RemoveAt(int index) - { - throw new NotSupportedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs index 98d5aa93cdec..5a9db328f6a4 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs @@ -95,29 +95,6 @@ public async Task MapAction_ExplicitQueryParam_StringReturn(string source, strin await VerifyResponseBodyAsync(httpContext, expectedBody, expectedStatusCode); } - [Fact] - public async Task MapAction_SingleDateOnlyParam_StringReturn() - { - var (results, compilation) = await RunGeneratorAsync(""" -app.MapGet("/hello", ([FromQuery]DateOnly p) => p.ToString("yyyy-MM-dd")); -"""); - var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); - var endpoint = GetEndpointFromCompilation(compilation); - - Assert.Equal("/hello", endpointModel.RoutePattern); - Assert.Equal("MapGet", endpointModel.HttpMethod); - var p = Assert.Single(endpointModel.Parameters); - Assert.Equal(EndpointParameterSource.Query, p.Source); - Assert.Equal("p", p.Name); - - var httpContext = CreateHttpContext(); - httpContext.Request.QueryString = new QueryString("?p=2023-02-20"); - - await endpoint.RequestDelegate(httpContext); - await VerifyResponseBodyAsync(httpContext, "2023-02-20"); - await VerifyAgainstBaselineUsingFile(compilation); - } - [Fact] public async Task MapAction_SingleTimeOnlyParam_StringReturn() { @@ -141,34 +118,14 @@ public async Task MapAction_SingleTimeOnlyParam_StringReturn() await VerifyAgainstBaselineUsingFile(compilation); } - [Fact] - public async Task MapAction_SingleDateTimeParam_StringReturn() - { - var (results, compilation) = await RunGeneratorAsync(""" -app.MapGet("/hello", ([FromQuery]DateTime p) => p.ToString("yyyy-MM-dd")); -"""); - var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); - var endpoint = GetEndpointFromCompilation(compilation); - - Assert.Equal("/hello", endpointModel.RoutePattern); - Assert.Equal("MapGet", endpointModel.HttpMethod); - var p = Assert.Single(endpointModel.Parameters); - Assert.Equal(EndpointParameterSource.Query, p.Source); - Assert.Equal("p", p.Name); - - var httpContext = CreateHttpContext(); - httpContext.Request.QueryString = new QueryString("?p=2023-02-20"); - - await endpoint.RequestDelegate(httpContext); - await VerifyResponseBodyAsync(httpContext, "2023-02-20"); - await VerifyAgainstBaselineUsingFile(compilation); - } - - [Fact] - public async Task MapAction_SingleDateTimeOffsetParam_StringReturn() + [Theory] + [InlineData("DateOnly", "2023-02-20")] + [InlineData("DateTime", "2023-02-20")] + [InlineData("DateTimeOffset", "2023-02-20")] + public async Task MapAction_SingleDateLikeParam_StringReturn(string parameterType, string result) { - var (results, compilation) = await RunGeneratorAsync(""" -app.MapGet("/hello", ([FromQuery]DateTimeOffset p) => p.ToString("yyyy-MM-dd")); + var (results, compilation) = await RunGeneratorAsync($$""" +app.MapGet("/hello", ([FromQuery]{{parameterType}} p) => p.ToString("yyyy-MM-dd")); """); var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); var endpoint = GetEndpointFromCompilation(compilation); @@ -180,11 +137,10 @@ public async Task MapAction_SingleDateTimeOffsetParam_StringReturn() Assert.Equal("p", p.Name); var httpContext = CreateHttpContext(); - httpContext.Request.QueryString = new QueryString("?p=2023-02-20"); + httpContext.Request.QueryString = new QueryString($"?p={result}"); await endpoint.RequestDelegate(httpContext); - await VerifyResponseBodyAsync(httpContext, "2023-02-20"); - await VerifyAgainstBaselineUsingFile(compilation); + await VerifyResponseBodyAsync(httpContext, result); } [Theory] @@ -230,7 +186,6 @@ public async Task MapAction_SingleNumericParam_StringReturn(string numericType) await endpoint.RequestDelegate(httpContext); await VerifyResponseBodyAsync(httpContext, "42"); - await VerifyAgainstBaselineUsingFile(compilation); } [Theory] @@ -256,7 +211,6 @@ public async Task MapAction_TryParsePrecedenceCheck(string parameterType, string await endpoint.RequestDelegate(httpContext); await VerifyResponseBodyAsync(httpContext, result); - await VerifyAgainstBaselineUsingFile(compilation); } [Fact] From 1548ffc5357d953da07d136784df3670e6b2f208 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Thu, 23 Feb 2023 09:37:58 +1100 Subject: [PATCH 06/11] Apply suggestions from code review Co-authored-by: Stephen Halter --- src/Shared/RoslynUtils/ParsabilityHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shared/RoslynUtils/ParsabilityHelper.cs b/src/Shared/RoslynUtils/ParsabilityHelper.cs index 7ed05a719eb1..6258c8ca3267 100644 --- a/src/Shared/RoslynUtils/ParsabilityHelper.cs +++ b/src/Shared/RoslynUtils/ParsabilityHelper.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Analyzers.Infrastructure; internal static class ParsabilityHelper { - private static bool IsTypeAlwaysParsableOrBindable(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes, out ParsabilityMethod? parsabilityMethod) + private static bool IsTypeAlwaysParsableOrBindable(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes, [NotNullWhen(true)] out ParsabilityMethod? parsabilityMethod) { // Any enum is valid. if (typeSymbol.TypeKind == TypeKind.Enum) From 70b8732fd48923982fc0f592f287716d8d5672c3 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Thu, 23 Feb 2023 09:39:15 +1100 Subject: [PATCH 07/11] Update src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs Co-authored-by: Stephen Halter --- .../gen/StaticRouteHandlerModel/EndpointParameter.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs index c04730fb53ba..67361dd4402d 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs @@ -94,7 +94,11 @@ private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes ParsabilityMethod.TryParseWithFormatProvider => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", ParsabilityMethod.TryParse => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, out var {{outputArgument}})""", ParsabilityMethod.Enum => (string inputArgument, string outputArgument) => $$"""Enum.TryParse<{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}>({{inputArgument}}, out var {{outputArgument}})""", - _ => null // ... everything that is parsable is covered above except strings ... + ParsabilityMethod.Uri => (string inputArgument, string outputArgument) => $$"""Uri.TryCreate({{inputArgument}}, UriKind.RelativeOrAbsolute, out var {{outputArgument}})""", + ParsabilityMethod.String => null, // string parameters don't require parsing + Parsability.NotParsable => null, + // The following is probably unnecessary. Would usually be an UnreachableException. + // _ => throw new Exception("Unreachable!"), }; // ... so for strings (null) we bail. From aa5d9059dfc0d661ca910f453e045e9eca34e7f2 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Thu, 23 Feb 2023 14:24:45 +1100 Subject: [PATCH 08/11] WIP: Working on reusing test cases from RDF. --- .../EndpointParameter.cs | 17 ++-- .../RequestDelegateGeneratorTestBase.cs | 6 ++ .../RequestDelegateGeneratorTests.cs | 87 ++++++++++++------- src/Shared/RoslynUtils/ParsabilityHelper.cs | 1 + src/Shared/RoslynUtils/ParsabilityMethod.cs | 1 - src/Shared/RoslynUtils/SymbolExtensions.cs | 23 +++++ 6 files changed, 94 insertions(+), 41 deletions(-) diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs index 67361dd4402d..ab47a0a27b4d 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs @@ -74,12 +74,14 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKnownTypes, [NotNullWhen(true)]out Func? parsingBlockEmitter) { + var parameterType = parameter.Type.UnwrapTypeSymbol(); + // ParsabilityHelper returns a single enumeration with a Parsable/NonParsable enumeration result. We use this already // in the analyzers to determine whether we need to warn on whether a type needs to implement TryParse/IParsable. To // support usage in the code generator an optiona out parameter has been added to hint at what variant of the various // TryParse methods should be used (this implies that the preferences are baked into ParsabilityHelper). If we aren't // parsable at all we bail. - if (ParsabilityHelper.GetParsability(parameter.Type, wellKnownTypes, out var parsabilityMethod) == Parsability.NotParsable) + if (ParsabilityHelper.GetParsability(parameterType, wellKnownTypes, out var parsabilityMethod) == Parsability.NotParsable) { parsingBlockEmitter = null; return false; @@ -90,15 +92,13 @@ private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes // which method was encountered. Func? preferredTryParseInvocation = parsabilityMethod switch { - ParsabilityMethod.IParsable => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", - ParsabilityMethod.TryParseWithFormatProvider => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", - ParsabilityMethod.TryParse => (string inputArgument, string outputArgument) => $$"""{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, out var {{outputArgument}})""", - ParsabilityMethod.Enum => (string inputArgument, string outputArgument) => $$"""Enum.TryParse<{{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}>({{inputArgument}}, out var {{outputArgument}})""", + ParsabilityMethod.IParsable => (string inputArgument, string outputArgument) => $$"""{{parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", + ParsabilityMethod.TryParseWithFormatProvider => (string inputArgument, string outputArgument) => $$"""{{parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, out var {{outputArgument}})""", + ParsabilityMethod.TryParse => (string inputArgument, string outputArgument) => $$"""{{parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, out var {{outputArgument}})""", + ParsabilityMethod.Enum => (string inputArgument, string outputArgument) => $$"""Enum.TryParse<{{parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}>({{inputArgument}}, out var {{outputArgument}})""", ParsabilityMethod.Uri => (string inputArgument, string outputArgument) => $$"""Uri.TryCreate({{inputArgument}}, UriKind.RelativeOrAbsolute, out var {{outputArgument}})""", ParsabilityMethod.String => null, // string parameters don't require parsing - Parsability.NotParsable => null, - // The following is probably unnecessary. Would usually be an UnreachableException. - // _ => throw new Exception("Unreachable!"), + _ => null }; // ... so for strings (null) we bail. @@ -116,6 +116,7 @@ private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes } """; return true; + } public ITypeSymbol Type { get; } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs index b9a57c00683c..a22cfae0eb2c 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs @@ -190,6 +190,11 @@ private static string GetMapActionString(string sources) => $$""" using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; +using System.Reflection; +using System.Reflection.Metadata; +using System.Net; +using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -248,6 +253,7 @@ internal async Task VerifyAgainstBaselineUsingFile(Compilation compilation, [Cal var baselineFilePath = Path.Combine("RequestDelegateGenerator", "Baselines", $"{callerName}.generated.txt"); var generatedSyntaxTree = compilation.SyntaxTrees.Last(); var generatedCode = await generatedSyntaxTree.GetTextAsync(); + await File.WriteAllTextAsync(baselineFilePath, generatedCode.ToString()); var baseline = await File.ReadAllTextAsync(baselineFilePath); var expectedLines = baseline .TrimEnd() // Trim newlines added by autoformat diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs index 5a9db328f6a4..726ccfe2e7bc 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs @@ -2,7 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; +using System; using System.Globalization; +using System.Net.Sockets; +using System.Net; +using System.Numerics; +using System.Reflection.Metadata; +using System.Reflection; using System.Text.Json; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Generators.StaticRouteHandlerModel; @@ -143,49 +149,66 @@ public async Task MapAction_SingleDateLikeParam_StringReturn(string parameterTyp await VerifyResponseBodyAsync(httpContext, result); } + public static object?[][] TryParsableParameters + { + get + { + var now = DateTime.Now; + + return new[] + { + // string is not technically "TryParsable", but it's the special case. + new object[] { "string", "plain string", "plain string" }, + new object[] { "int", "-42", -42 }, + new object[] { "uint", "42", 42U }, + new object[] { "bool", "true", true }, + new object[] { "short", "-42", (short)-42 }, + new object[] { "ushort", "42", (ushort)42 }, + new object[] { "long", "-42", -42L }, + new object[] { "ulong", "42", 42UL }, + new object[] { "IntPtr", "-42", new IntPtr(-42) }, + //new object[] { "char", "A", 'A' }, + new object[] { "double", "0.5", 0.5 }, + new object[] { "float", "0.5", 0.5f }, + new object[] { "Half", "0.5", (Half)0.5f }, + new object[] { "decimal", "0.5", 0.5m }, + new object[] { "Uri", "https://example.org", new Uri("https://example.org") }, + //new object[] { "DateTime", now.ToString("o"), now.ToUniversalTime() }, + //new object[] { "DateTimeOffset", "1970-01-01T00:00:00.0000000+00:00", DateTimeOffset.UnixEpoch }, + new object[] { "TimeSpan", "00:00:42", TimeSpan.FromSeconds(42) }, + new object[] { "Guid", "00000000-0000-0000-0000-000000000000", Guid.Empty }, + new object[] { "Version", "6.0.0.42", new Version("6.0.0.42") }, + new object[] { "BigInteger", "-42", new BigInteger(-42) }, + new object[] { "IPAddress", "127.0.0.1", IPAddress.Loopback }, + new object[] { "IPEndPoint", "127.0.0.1:80", new IPEndPoint(IPAddress.Loopback, 80) }, + new object[] { "AddressFamily", "Unix", AddressFamily.Unix }, + new object[] { "ILOpCode", "Nop", ILOpCode.Nop }, + new object[] { "AssemblyFlags", "PublicKey,Retargetable", AssemblyFlags.PublicKey | AssemblyFlags.Retargetable }, + new object[] { "int?", "42", 42 }, + new object?[] { "int?", null, null }, + }; + } + } + [Theory] - [InlineData("sbyte")] - [InlineData("SByte")] - [InlineData("byte")] - [InlineData("Byte")] - [InlineData("short")] - [InlineData("Int16")] - [InlineData("ushort")] - [InlineData("UInt16")] - [InlineData("int")] - [InlineData("Int32")] - [InlineData("uint")] - [InlineData("UInt32")] - [InlineData("long")] - [InlineData("Int64")] - [InlineData("ulong")] - [InlineData("UInt64")] - [InlineData("float")] - [InlineData("Single")] - [InlineData("double")] - [InlineData("Double")] - [InlineData("decimal")] - [InlineData("Decimal")] - public async Task MapAction_SingleNumericParam_StringReturn(string numericType) + [MemberData(nameof(TryParsableParameters))] + public async Task MapAction_SingleParsable_StringReturn(string typeName, string queryStringInput, object? expectedParameterValue) { var (results, compilation) = await RunGeneratorAsync($$""" -app.MapGet("/hello", ([FromQuery]{{numericType}} p) => p.ToString()); +app.MapGet("/hello", (HttpContext context, [FromQuery]{{typeName}} p) => +{ + context.Items["tryParsable"] = p; +}); """); var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); var endpoint = GetEndpointFromCompilation(compilation); - Assert.Equal("/hello", endpointModel.RoutePattern); - Assert.Equal("MapGet", endpointModel.HttpMethod); - var p = Assert.Single(endpointModel.Parameters); - Assert.Equal(EndpointParameterSource.Query, p.Source); - Assert.Equal("p", p.Name); - var httpContext = CreateHttpContext(); - httpContext.Request.QueryString = new QueryString("?p=42"); + httpContext.Request.QueryString = new QueryString($"?p={queryStringInput}"); await endpoint.RequestDelegate(httpContext); - await VerifyResponseBodyAsync(httpContext, "42"); + Assert.Equal(expectedParameterValue, httpContext.Items["tryParsable"]); } [Theory] diff --git a/src/Shared/RoslynUtils/ParsabilityHelper.cs b/src/Shared/RoslynUtils/ParsabilityHelper.cs index 6258c8ca3267..c23425b8e224 100644 --- a/src/Shared/RoslynUtils/ParsabilityHelper.cs +++ b/src/Shared/RoslynUtils/ParsabilityHelper.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.App.Analyzers.Infrastructure; using Microsoft.AspNetCore.Analyzers.RouteEmbeddedLanguage.Infrastructure; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.AspNetCore.Analyzers.Infrastructure; diff --git a/src/Shared/RoslynUtils/ParsabilityMethod.cs b/src/Shared/RoslynUtils/ParsabilityMethod.cs index 216df132f9f2..e4b9fbe23064 100644 --- a/src/Shared/RoslynUtils/ParsabilityMethod.cs +++ b/src/Shared/RoslynUtils/ParsabilityMethod.cs @@ -5,7 +5,6 @@ namespace Microsoft.AspNetCore.Analyzers.Infrastructure; internal enum ParsabilityMethod { - NotParsable, String, IParsable, Enum, diff --git a/src/Shared/RoslynUtils/SymbolExtensions.cs b/src/Shared/RoslynUtils/SymbolExtensions.cs index 1809be26edc7..7c73a703a73a 100644 --- a/src/Shared/RoslynUtils/SymbolExtensions.cs +++ b/src/Shared/RoslynUtils/SymbolExtensions.cs @@ -11,6 +11,29 @@ namespace Microsoft.AspNetCore.Analyzers.RouteEmbeddedLanguage.Infrastructure; internal static class SymbolExtensions { + public static INamedTypeSymbol? UnwrapTypeSymbol(this ITypeSymbol typeSymbol) + { + INamedTypeSymbol? unwrappedTypeSymbol = null; + + // If it is an array, unwrap it. + if (typeSymbol is IArrayTypeSymbol arrayTypeSymbol) + { + unwrappedTypeSymbol = arrayTypeSymbol.ElementType as INamedTypeSymbol; + } + else if (typeSymbol is INamedTypeSymbol namedTypeSymbol) + { + unwrappedTypeSymbol = namedTypeSymbol; + } + + // If it is nullable, unwrap it. + if (unwrappedTypeSymbol!.ConstructedFrom.SpecialType == SpecialType.System_Nullable_T) + { + unwrappedTypeSymbol = unwrappedTypeSymbol.TypeArguments[0] as INamedTypeSymbol; + } + + return unwrappedTypeSymbol; + } + public static bool HasAttribute(this ISymbol symbol, INamedTypeSymbol attributeType) { foreach (var attributeData in symbol.GetAttributes()) From 8a1a3c9cd03687013b383740655149614e7f5d5b Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Fri, 24 Feb 2023 13:03:21 +1100 Subject: [PATCH 09/11] Handle RDF TryParse binding test cases. --- .../Emitters/EndpointParameterEmitter.cs | 10 ++-- .../EndpointParameter.cs | 48 +++++++++++++++++-- .../RequestDelegateGeneratorTests.cs | 17 ++++--- src/Shared/RoslynUtils/WellKnownTypeData.cs | 4 ++ 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs index 43fe9f0faaad..ba564c643152 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs @@ -3,6 +3,7 @@ using System; using System.Text; +using Microsoft.CodeAnalysis; namespace Microsoft.AspNetCore.Http.Generators.StaticRouteHandlerModel.Emitters; internal static class EndpointParameterEmitter @@ -65,18 +66,16 @@ internal static string EmitParsingBlock(this EndpointParameter endpointParameter var parsingBlock = endpointParameter.ParsingBlockEmitter($"{endpointParameter.Name}_temp", $"{endpointParameter.Name}_parsed_temp"); builder.AppendLine($$""" {{parsingBlock}} - var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.Name}}_parsed_temp!; + {{endpointParameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}} {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.Name}}_parsed_temp!; """); } else { builder.AppendLine($$""" - var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.Name}}_temp; + {{endpointParameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}} {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.Name}}_temp!; """); - } - return builder.ToString(); } internal static string EmitRouteParameterPreparation(this EndpointParameter endpointParameter) @@ -199,8 +198,6 @@ internal static string EmitServiceParameterPreparation(this EndpointParameter en } private static string EmitParameterDiagnosticComment(this EndpointParameter endpointParameter) => - $"// Endpoint Parameter: {endpointParameter.Name} (Type = {endpointParameter.Type.ToDisplayString(EmitterConstants.DisplayFormat)}, IsOptional = {endpointParameter.IsOptional}, Source = {endpointParameter.Source})"; - private static string EmitHandlerArgument(this EndpointParameter endpointParameter) => $"{endpointParameter.Name}_local"; private static string EmitAssigningCodeResult(this EndpointParameter endpointParameter) => $"{endpointParameter.Name}_raw"; @@ -212,4 +209,3 @@ private static string EmitParameterDiagnosticComment(this EndpointParameter endp EndpointParameterSource.Unknown => throw new Exception("Unreachable!"), _ => endpointParameter.EmitHandlerArgument() }; -} diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs index ab47a0a27b4d..fe2056205c0d 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs @@ -8,6 +8,8 @@ using Microsoft.CodeAnalysis; using WellKnownType = Microsoft.AspNetCore.App.Analyzers.Infrastructure.WellKnownTypeData.WellKnownType; using Microsoft.AspNetCore.Analyzers.Infrastructure; +using System.Linq; +using System.Globalization; namespace Microsoft.AspNetCore.Http.Generators.StaticRouteHandlerModel; @@ -72,7 +74,7 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp } } - private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKnownTypes, [NotNullWhen(true)]out Func? parsingBlockEmitter) + private bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKnownTypes, [NotNullWhen(true)]out Func? parsingBlockEmitter) { var parameterType = parameter.Type.UnwrapTypeSymbol(); @@ -101,6 +103,24 @@ private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes _ => null }; + // Special case handling for specific types + if (parameterType.SpecialType == SpecialType.System_Char) + { + preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""{{parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, out var {{outputArgument}})"""; + } + else if (parameterType.SpecialType == SpecialType.System_DateTime) + { + preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""{{parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AllowWhiteSpaces, out var {{outputArgument}})"""; + } + else if (SymbolEqualityComparer.Default.Equals(parameterType, wellKnownTypes.Get(WellKnownType.System_DateTimeOffset))) + { + preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""{{parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AllowWhiteSpaces, out var {{outputArgument}})"""; + } + else if (SymbolEqualityComparer.Default.Equals(parameterType, wellKnownTypes.Get(WellKnownType.System_DateOnly))) + { + preferredTryParseInvocation = (string inputArgument, string outputArgument) => $$"""{{parameterType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}}.TryParse({{inputArgument}}, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out var {{outputArgument}})"""; + } + // ... so for strings (null) we bail. if (preferredTryParseInvocation == null) { @@ -108,13 +128,35 @@ private static bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes return false; } - // Wrap the TryParse method call in an if-block and if it doesn't work set param check failure. - parsingBlockEmitter = (inputArgument, outputArgument) => $$""" + if (IsOptional) + { + parsingBlockEmitter = (inputArgument, outputArgument) => $$""" + {{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}} {{outputArgument}} = default; + if ({{preferredTryParseInvocation(inputArgument, $"{inputArgument}_parsed_non_nullable")}}) + { + {{outputArgument}} = {{$"{inputArgument}_parsed_non_nullable"}}; + } + else if (string.IsNullOrEmpty({{inputArgument}})) + { + {{outputArgument}} = null; + } + else + { + wasParamCheckFailure = true; + } +"""; + } + else + { + parsingBlockEmitter = (inputArgument, outputArgument) => $$""" if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}}) { wasParamCheckFailure = true; } """; + } + + // Wrap the TryParse method call in an if-block and if it doesn't work set param check failure. return true; } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs index 726ccfe2e7bc..9b74bcb164a8 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs @@ -15,6 +15,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.DependencyInjection; +using System.Text.Encodings.Web; +using Microsoft.AspNetCore.WebUtilities; +using Microsoft.Extensions.WebEncoders.Testing; namespace Microsoft.AspNetCore.Http.Generators.Tests; @@ -157,7 +160,7 @@ public static object?[][] TryParsableParameters return new[] { - // string is not technically "TryParsable", but it's the special case. + //// string is not technically "TryParsable", but it's the special case. new object[] { "string", "plain string", "plain string" }, new object[] { "int", "-42", -42 }, new object[] { "uint", "42", 42U }, @@ -167,14 +170,14 @@ public static object?[][] TryParsableParameters new object[] { "long", "-42", -42L }, new object[] { "ulong", "42", 42UL }, new object[] { "IntPtr", "-42", new IntPtr(-42) }, - //new object[] { "char", "A", 'A' }, + new object[] { "char", "A", 'A' }, new object[] { "double", "0.5", 0.5 }, new object[] { "float", "0.5", 0.5f }, new object[] { "Half", "0.5", (Half)0.5f }, new object[] { "decimal", "0.5", 0.5m }, new object[] { "Uri", "https://example.org", new Uri("https://example.org") }, - //new object[] { "DateTime", now.ToString("o"), now.ToUniversalTime() }, - //new object[] { "DateTimeOffset", "1970-01-01T00:00:00.0000000+00:00", DateTimeOffset.UnixEpoch }, + new object[] { "DateTime", now.ToString("o"), now.ToUniversalTime() }, + new object[] { "DateTimeOffset", "1970-01-01T00:00:00.0000000+00:00", DateTimeOffset.UnixEpoch }, new object[] { "TimeSpan", "00:00:42", TimeSpan.FromSeconds(42) }, new object[] { "Guid", "00000000-0000-0000-0000-000000000000", Guid.Empty }, new object[] { "Version", "6.0.0.42", new Version("6.0.0.42") }, @@ -203,11 +206,13 @@ public async Task MapAction_SingleParsable_StringReturn(string typeName, string var endpointModel = GetStaticEndpoint(results, GeneratorSteps.EndpointModelStep); var endpoint = GetEndpointFromCompilation(compilation); - var httpContext = CreateHttpContext(); - httpContext.Request.QueryString = new QueryString($"?p={queryStringInput}"); + + var encodedQueryStringInput = queryStringInput != null ? UrlEncoder.Default.Encode(queryStringInput) : null; + httpContext.Request.QueryString = new QueryString($"?p={encodedQueryStringInput}"); await endpoint.RequestDelegate(httpContext); + Assert.Equal(200, httpContext.Response.StatusCode); Assert.Equal(expectedParameterValue, httpContext.Items["tryParsable"]); } diff --git a/src/Shared/RoslynUtils/WellKnownTypeData.cs b/src/Shared/RoslynUtils/WellKnownTypeData.cs index 8632c5b66f2f..eb8337a24cf8 100644 --- a/src/Shared/RoslynUtils/WellKnownTypeData.cs +++ b/src/Shared/RoslynUtils/WellKnownTypeData.cs @@ -28,6 +28,8 @@ public enum WellKnownType System_Security_Claims_ClaimsPrincipal, Microsoft_AspNetCore_Http_IFormFileCollection, Microsoft_AspNetCore_Http_IFormFile, + System_DateOnly, + System_DateTimeOffset, System_IO_Stream, System_IO_Pipelines_PipeReader, System_IFormatProvider, @@ -129,6 +131,8 @@ public enum WellKnownType "System.Security.Claims.ClaimsPrincipal", "Microsoft.AspNetCore.Http.IFormFileCollection", "Microsoft.AspNetCore.Http.IFormFile", + "System.DateOnly", + "System.DateTimeOffset", "System.IO.Stream", "System.IO.Pipelines.PipeReader", "System.IFormatProvider", From 2495d891afe8b69090700f2d1e8bab33c9756899 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Fri, 24 Feb 2023 14:39:56 +1100 Subject: [PATCH 10/11] Fix compiler errors. --- .../RequestDelegateGeneratorTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs index 9b74bcb164a8..7747f5ab050f 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs @@ -152,7 +152,7 @@ public async Task MapAction_SingleDateLikeParam_StringReturn(string parameterTyp await VerifyResponseBodyAsync(httpContext, result); } - public static object?[][] TryParsableParameters + public static object[][] TryParsableParameters { get { @@ -188,14 +188,14 @@ public static object?[][] TryParsableParameters new object[] { "ILOpCode", "Nop", ILOpCode.Nop }, new object[] { "AssemblyFlags", "PublicKey,Retargetable", AssemblyFlags.PublicKey | AssemblyFlags.Retargetable }, new object[] { "int?", "42", 42 }, - new object?[] { "int?", null, null }, + new object[] { "int?", null, null }, }; } } [Theory] [MemberData(nameof(TryParsableParameters))] - public async Task MapAction_SingleParsable_StringReturn(string typeName, string queryStringInput, object? expectedParameterValue) + public async Task MapAction_SingleParsable_StringReturn(string typeName, string queryStringInput, object expectedParameterValue) { var (results, compilation) = await RunGeneratorAsync($$""" app.MapGet("/hello", (HttpContext context, [FromQuery]{{typeName}} p) => From 8ba7574e6c4ae95a0622dc8669765de6767e334e Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 27 Feb 2023 12:12:22 +1100 Subject: [PATCH 11/11] Rebase on Safia's changes. --- .../Emitters/EndpointParameterEmitter.cs | 146 +++++++++--------- .../RequestDelegateGeneratorTestBase.cs | 103 ++++++++++++ 2 files changed, 176 insertions(+), 73 deletions(-) diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs index ba564c643152..8de76e326ce9 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs @@ -36,8 +36,7 @@ internal static string EmitQueryOrHeaderParameterPreparation(this EndpointParame if (endpointParameter.IsOptional) { builder.AppendLine($$""" - var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.EmitAssigningCodeResult()}}.Count > 0 ? {{endpointParameter.EmitAssigningCodeResult()}}.ToString() : null; - var {{endpointParameter.Name}}_temp = {{endpointParameter.Name}}_raw.Count > 0 ? {{endpointParameter.Name}}_raw.ToString() : null; + var {{endpointParameter.Name}}_temp = {{endpointParameter.EmitAssigningCodeResult()}}.Count > 0 ? {{endpointParameter.Name}}_raw.ToString() : null; """); } else @@ -47,7 +46,6 @@ internal static string EmitQueryOrHeaderParameterPreparation(this EndpointParame { wasParamCheckFailure = true; } - var {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.EmitAssigningCodeResult()}}.ToString(); var {{endpointParameter.Name}}_temp = {{endpointParameter.EmitAssigningCodeResult()}}.ToString(); """); } @@ -76,136 +74,138 @@ internal static string EmitParsingBlock(this EndpointParameter endpointParameter {{endpointParameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}} {{endpointParameter.EmitHandlerArgument()}} = {{endpointParameter.Name}}_temp!; """); + } + + return builder.ToString(); } - internal static string EmitRouteParameterPreparation(this EndpointParameter endpointParameter) - { - var builder = new StringBuilder(); - builder.AppendLine($""" + internal static string EmitRouteParameterPreparation(this EndpointParameter endpointParameter) + { + var builder = new StringBuilder(); + builder.AppendLine($""" {endpointParameter.EmitParameterDiagnosticComment()} """); - // Throw an exception of if the route parameter name that was specific in the `FromRoute` - // attribute or in the parameter name does not appear in the actual route. - builder.AppendLine($$""" + // Throw an exception of if the route parameter name that was specific in the `FromRoute` + // attribute or in the parameter name does not appear in the actual route. + builder.AppendLine($$""" if (options?.RouteParameterNames?.Contains("{{endpointParameter.Name}}", StringComparer.OrdinalIgnoreCase) != true) { throw new InvalidOperationException($"'{{endpointParameter.Name}}' is not a route parameter."); } """); - var assigningCode = $"httpContext.Request.RouteValues[\"{endpointParameter.Name}\"]?.ToString()"; - builder.AppendLine($$""" + var assigningCode = $"httpContext.Request.RouteValues[\"{endpointParameter.Name}\"]?.ToString()"; + builder.AppendLine($$""" var {{endpointParameter.EmitAssigningCodeResult()}} = {{assigningCode}}; """); - if (!endpointParameter.IsOptional) - { - builder.AppendLine($$""" + if (!endpointParameter.IsOptional) + { + builder.AppendLine($$""" if ({{endpointParameter.EmitAssigningCodeResult()}} == null) { wasParamCheckFailure = true; } """); - } - builder.AppendLine($""" + } + builder.AppendLine($""" var {endpointParameter.EmitHandlerArgument()} = {endpointParameter.EmitAssigningCodeResult()}; """); - return builder.ToString(); - } + return builder.ToString(); + } - internal static string EmitRouteOrQueryParameterPreparation(this EndpointParameter endpointParameter) - { - var builder = new StringBuilder(); - builder.AppendLine($""" + internal static string EmitRouteOrQueryParameterPreparation(this EndpointParameter endpointParameter) + { + var builder = new StringBuilder(); + builder.AppendLine($""" {endpointParameter.EmitParameterDiagnosticComment()} """); - var parameterName = endpointParameter.Name; - var assigningCode = $@"options?.RouteParameterNames?.Contains(""{parameterName}"", StringComparer.OrdinalIgnoreCase) == true"; - assigningCode += $@"? new StringValues(httpContext.Request.RouteValues[$""{parameterName}""]?.ToString())"; - assigningCode += $@": httpContext.Request.Query[$""{parameterName}""];"; + var parameterName = endpointParameter.Name; + var assigningCode = $@"options?.RouteParameterNames?.Contains(""{parameterName}"", StringComparer.OrdinalIgnoreCase) == true"; + assigningCode += $@"? new StringValues(httpContext.Request.RouteValues[$""{parameterName}""]?.ToString())"; + assigningCode += $@": httpContext.Request.Query[$""{parameterName}""];"; - builder.AppendLine($$""" + builder.AppendLine($$""" var {{endpointParameter.EmitAssigningCodeResult()}} = {{assigningCode}}; """); - if (!endpointParameter.IsOptional) - { - builder.AppendLine($$""" + if (!endpointParameter.IsOptional) + { + builder.AppendLine($$""" if ({{endpointParameter.EmitAssigningCodeResult()}} is StringValues { Count: 0 }) { wasParamCheckFailure = true; } """); - } + } - builder.AppendLine($""" + builder.AppendLine($""" var {endpointParameter.EmitHandlerArgument()} = {endpointParameter.EmitAssigningCodeResult()}; """); - return builder.ToString(); - } + return builder.ToString(); + } - internal static string EmitJsonBodyParameterPreparationString(this EndpointParameter endpointParameter) - { - var builder = new StringBuilder(); - builder.AppendLine($""" + internal static string EmitJsonBodyParameterPreparationString(this EndpointParameter endpointParameter) + { + var builder = new StringBuilder(); + builder.AppendLine($""" {endpointParameter.EmitParameterDiagnosticComment()} """); - var assigningCode = $"await GeneratedRouteBuilderExtensionsCore.TryResolveBody<{endpointParameter.Type.ToDisplayString(EmitterConstants.DisplayFormat)}>(httpContext, {(endpointParameter.IsOptional ? "true" : "false")})"; - builder.AppendLine($$""" + var assigningCode = $"await GeneratedRouteBuilderExtensionsCore.TryResolveBody<{endpointParameter.Type.ToDisplayString(EmitterConstants.DisplayFormat)}>(httpContext, {(endpointParameter.IsOptional ? "true" : "false")})"; + builder.AppendLine($$""" var (isSuccessful, {{endpointParameter.EmitHandlerArgument()}}) = {{assigningCode}}; """); - // If binding from the JSON body fails, we exit early. Don't - // set the status code here because assume it has been set by the - // TryResolveBody method. - builder.AppendLine(""" + // If binding from the JSON body fails, we exit early. Don't + // set the status code here because assume it has been set by the + // TryResolveBody method. + builder.AppendLine(""" if (!isSuccessful) { return; } """); - return builder.ToString(); - } + return builder.ToString(); + } - internal static string EmitServiceParameterPreparation(this EndpointParameter endpointParameter) - { - var builder = new StringBuilder(); + internal static string EmitServiceParameterPreparation(this EndpointParameter endpointParameter) + { + var builder = new StringBuilder(); - // Preamble for diagnostics purposes. - builder.AppendLine($""" + // Preamble for diagnostics purposes. + builder.AppendLine($""" {endpointParameter.EmitParameterDiagnosticComment()} """); - // Requiredness checks for services are handled by the distinction - // between GetRequiredService and GetService in the assigningCode. - // Unlike other scenarios, this will result in an exception being thrown - // at runtime. - var assigningCode = endpointParameter.IsOptional ? - $"httpContext.RequestServices.GetService<{endpointParameter.Type}>();" : - $"httpContext.RequestServices.GetRequiredService<{endpointParameter.Type}>()"; + // Requiredness checks for services are handled by the distinction + // between GetRequiredService and GetService in the assigningCode. + // Unlike other scenarios, this will result in an exception being thrown + // at runtime. + var assigningCode = endpointParameter.IsOptional ? + $"httpContext.RequestServices.GetService<{endpointParameter.Type}>();" : + $"httpContext.RequestServices.GetRequiredService<{endpointParameter.Type}>()"; - builder.AppendLine($$""" + builder.AppendLine($$""" var {{endpointParameter.EmitHandlerArgument()}} = {{assigningCode}}; """); - return builder.ToString(); - } + return builder.ToString(); + } - private static string EmitParameterDiagnosticComment(this EndpointParameter endpointParameter) => - private static string EmitHandlerArgument(this EndpointParameter endpointParameter) => $"{endpointParameter.Name}_local"; - private static string EmitAssigningCodeResult(this EndpointParameter endpointParameter) => $"{endpointParameter.Name}_raw"; + private static string EmitParameterDiagnosticComment(this EndpointParameter endpointParameter) => $"// Endpoint Parameter: {endpointParameter.Name} (Type = {endpointParameter.Type}, IsOptional = {endpointParameter.IsOptional}, IsParsable = {endpointParameter.IsParsable}, Source = {endpointParameter.Source})"; + private static string EmitHandlerArgument(this EndpointParameter endpointParameter) => $"{endpointParameter.Name}_local"; + private static string EmitAssigningCodeResult(this EndpointParameter endpointParameter) => $"{endpointParameter.Name}_raw"; - public static string EmitArgument(this EndpointParameter endpointParameter) => endpointParameter.Source switch - { - EndpointParameterSource.JsonBody or EndpointParameterSource.Route or EndpointParameterSource.RouteOrQuery => endpointParameter.IsOptional - ? endpointParameter.EmitHandlerArgument() - : $"{endpointParameter.EmitHandlerArgument()}!", - EndpointParameterSource.Unknown => throw new Exception("Unreachable!"), - _ => endpointParameter.EmitHandlerArgument() - }; + public static string EmitArgument(this EndpointParameter endpointParameter) => endpointParameter.Source switch + { + EndpointParameterSource.JsonBody or EndpointParameterSource.Route or EndpointParameterSource.RouteOrQuery => endpointParameter.IsOptional ? endpointParameter.EmitHandlerArgument() : $"{endpointParameter.EmitHandlerArgument()}!", + EndpointParameterSource.Unknown => throw new Exception("Unreachable!"), + _ => endpointParameter.EmitHandlerArgument() + }; + } diff --git a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs index a22cfae0eb2c..b0d1e00a9b3d 100644 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs +++ b/src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTestBase.cs @@ -212,6 +212,109 @@ public static IEndpointRouteBuilder MapTestEndpoints(this IEndpointRouteBuilder return app; } } + +public enum TodoStatus +{ + Trap, // A trap for Enum.TryParse! + Done, + InProgress, + NotDone +} + +public interface ITodo +{ + public int Id { get; } + public string? Name { get; } + public bool IsComplete { get; } + public TodoStatus Status { get; } +} + +public class PrecedenceCheckTodo +{ + public PrecedenceCheckTodo(int magicValue) + { + MagicValue = magicValue; + } + public int MagicValue { get; } + public static bool TryParse(string? input, IFormatProvider? provider, out PrecedenceCheckTodo result) + { + result = new PrecedenceCheckTodo(42); + return true; + } + public static bool TryParse(string? input, out PrecedenceCheckTodo result) + { + result = new PrecedenceCheckTodo(24); + return true; + } +} + +public class PrecedenceCheckTodoWithoutFormat +{ + public PrecedenceCheckTodoWithoutFormat(int magicValue) + { + MagicValue = magicValue; + } + public int MagicValue { get; } + public static bool TryParse(string? input, out PrecedenceCheckTodoWithoutFormat result) + { + result = new PrecedenceCheckTodoWithoutFormat(24); + return true; + } +} + +public class ParsableTodo : IParsable +{ + public int Id { get; set; } + public string? Name { get; set; } = "Todo"; + public bool IsComplete { get; set; } + public static ParsableTodo Parse(string s, IFormatProvider? provider) + { + return new ParsableTodo(); + } + public static bool TryParse(string? input, IFormatProvider? provider, out ParsableTodo result) + { + if (input == "1") + { + result = new ParsableTodo + { + Id = 1, + Name = "Knit kitten mittens.", + IsComplete = false + }; + return true; + } + else + { + result = null!; + return false; + } + } +} + +public class Todo +{ + public int Id { get; set; } + public string? Name { get; set; } = "Todo"; + public bool IsComplete { get; set; } + public static bool TryParse(string input, out Todo? result) + { + if (input == "1") + { + result = new Todo + { + Id = 1, + Name = "Knit kitten mittens.", + IsComplete = false + }; + return true; + } + else + { + result = null; + return false; + } + } +} """; private static Task CreateCompilationAsync(string sources) {