diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs index ab5acc4d24af..ebdfaacf6632 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs @@ -44,8 +44,7 @@ internal static void EmitParsingBlock(this EndpointParameter endpointParameter, { if (endpointParameter.IsParsable) { - var parsingBlock = endpointParameter.ParsingBlockEmitter(endpointParameter.EmitTempArgument(), endpointParameter.EmitParsedTempArgument()); - codeWriter.WriteLine(parsingBlock); + endpointParameter.ParsingBlockEmitter(codeWriter, endpointParameter.EmitTempArgument(), endpointParameter.EmitParsedTempArgument()); codeWriter.WriteLine($"{endpointParameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} {endpointParameter.EmitHandlerArgument()} = {endpointParameter.EmitParsedTempArgument()}!;"); } else diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs index 792cce713d9f..19d861817a26 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs @@ -76,7 +76,7 @@ public EndpointParameter(IParameterSymbol parameter, WellKnownTypes wellKnownTyp } } - private bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKnownTypes, [NotNullWhen(true)]out Func? parsingBlockEmitter) + private bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKnownTypes, [NotNullWhen(true)]out Action? parsingBlockEmitter) { var parameterType = parameter.Type.UnwrapTypeSymbol(); @@ -132,35 +132,36 @@ private bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKn 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; - } -"""; + parsingBlockEmitter = (writer, inputArgument, outputArgument) => + { + writer.WriteLine($"""{parameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} {outputArgument} = default;"""); + writer.WriteLine($$"""if ({{preferredTryParseInvocation(inputArgument, $"{inputArgument}_parsed_non_nullable")}})"""); + writer.StartBlock(); + writer.WriteLine($$"""{{outputArgument}} = {{$"{inputArgument}_parsed_non_nullable"}};"""); + writer.EndBlock(); + writer.WriteLine($$"""else if (string.IsNullOrEmpty({{inputArgument}}))"""); + writer.StartBlock(); + writer.WriteLine($$"""{{outputArgument}} = null;"""); + writer.EndBlock(); + writer.WriteLine("else"); + writer.StartBlock(); + writer.WriteLine("wasParamCheckFailure = true;"); + writer.EndBlock(); + }; } else { - parsingBlockEmitter = (inputArgument, outputArgument) => $$""" - if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}}) - { - wasParamCheckFailure = true; - } -"""; + parsingBlockEmitter = (writer, inputArgument, outputArgument) => + { + writer.WriteLine($$"""if (!{{preferredTryParseInvocation(inputArgument, outputArgument)}})"""); + writer.StartBlock(); + writer.WriteLine("wasParamCheckFailure = true;"); + writer.EndBlock(); + }; } // Wrap the TryParse method call in an if-block and if it doesn't work set param check failure. return true; - } public ITypeSymbol Type { get; } @@ -173,7 +174,7 @@ private bool TryGetParsability(IParameterSymbol parameter, WellKnownTypes wellKn public bool IsOptional { get; } [MemberNotNull("ParsingBlockEmitter")] public bool IsParsable { get; } - public Func ParsingBlockEmitter { get; } + public Action 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_SingleComplexTypeParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt index bcc6b5601e54..26a8b1ea5f23 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 @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!global::Todo.TryParse(p_temp!, out var p_parsed_temp)) + if (!global::Todo.TryParse(p_temp!, out var p_parsed_temp)) { wasParamCheckFailure = true; } @@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!global::Todo.TryParse(p_temp!, out var p_parsed_temp)) + if (!global::Todo.TryParse(p_temp!, out var p_parsed_temp)) { wasParamCheckFailure = true; } 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 4309a5b3c9ab..2f069edd742f 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 @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!Enum.TryParse(p_temp!, out var p_parsed_temp)) + if (!Enum.TryParse(p_temp!, out var p_parsed_temp)) { wasParamCheckFailure = true; } @@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!Enum.TryParse(p_temp!, out var p_parsed_temp)) + if (!Enum.TryParse(p_temp!, out var p_parsed_temp)) { wasParamCheckFailure = true; } 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 deleted file mode 100644 index 62a2f093c726..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithQueryStringValueProvided_StringReturn.generated.txt +++ /dev/null @@ -1,1617 +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 = string?, IsOptional = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; - var p_local = p_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 = string?, IsOptional = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; - var p_local = p_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); - } - - private static StringValues ResolveFromRouteOrQuery(HttpContext httpContext, string parameterName, IEnumerable? routeParameterNames) - { - return routeParameterNames?.Contains(parameterName, StringComparer.OrdinalIgnoreCase) == true - ? new StringValues(httpContext.Request.RouteValues[$"{parameterName}"]?.ToString()) - : httpContext.Request.Query[$"{parameterName}"]; - } - } - - %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_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt deleted file mode 100644 index 62a2f093c726..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleNullableStringParam_WithoutQueryStringValueProvided_StringReturn.generated.txt +++ /dev/null @@ -1,1617 +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 = string?, IsOptional = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; - var p_local = p_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 = string?, IsOptional = True, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - var p_temp = p_raw.Count > 0 ? p_raw.ToString() : null; - var p_local = p_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); - } - - private static StringValues ResolveFromRouteOrQuery(HttpContext httpContext, string parameterName, IEnumerable? routeParameterNames) - { - return routeParameterNames?.Contains(parameterName, StringComparer.OrdinalIgnoreCase) == true - ? new StringValues(httpContext.Request.RouteValues[$"{parameterName}"]?.ToString()) - : httpContext.Request.Query[$"{parameterName}"]; - } - } - - %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 deleted file mode 100644 index c9c412d83e37..000000000000 --- a/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleStringParam_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 = string, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - var p_local = p_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 = string, IsOptional = False, Source = Query) - var p_raw = httpContext.Request.Query["p"]; - if (StringValues.IsNullOrEmpty(p_raw)) - { - wasParamCheckFailure = true; - } - var p_temp = p_raw.ToString(); - var p_local = p_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); - } - - private static StringValues ResolveFromRouteOrQuery(HttpContext httpContext, string parameterName, IEnumerable? routeParameterNames) - { - return routeParameterNames?.Contains(parameterName, StringComparer.OrdinalIgnoreCase) == true - ? new StringValues(httpContext.Request.RouteValues[$"{parameterName}"]?.ToString()) - : httpContext.Request.Query[$"{parameterName}"]; - } - } - - %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_SingleTimeOnlyParam_StringReturn.generated.txt b/src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleTimeOnlyParam_StringReturn.generated.txt index 8de0dbb8735d..98bc589f1f1b 100644 --- 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 @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!global::System.TimeOnly.TryParse(p_temp!, CultureInfo.InvariantCulture, out var p_parsed_temp)) + if (!global::System.TimeOnly.TryParse(p_temp!, CultureInfo.InvariantCulture, out var p_parsed_temp)) { wasParamCheckFailure = true; } @@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Http.Generated wasParamCheckFailure = true; } var p_temp = p_raw.ToString(); - if (!global::System.TimeOnly.TryParse(p_temp!, CultureInfo.InvariantCulture, out var p_parsed_temp)) + if (!global::System.TimeOnly.TryParse(p_temp!, CultureInfo.InvariantCulture, out var p_parsed_temp)) { wasParamCheckFailure = true; }