|
|
@@ -0,0 +1,195 @@
|
|
|
+//------------------------------------------------------------------------------
|
|
|
+// <auto-generated>
|
|
|
+// This code was generated by a tool.
|
|
|
+//
|
|
|
+// Changes to this file may cause incorrect behavior and will be lost if
|
|
|
+// the code is regenerated.
|
|
|
+// </auto-generated>
|
|
|
+//------------------------------------------------------------------------------
|
|
|
+#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<string, string, string> handler,
|
|
|
+ [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "",
|
|
|
+ [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0)
|
|
|
+ {
|
|
|
+ return global::Microsoft.AspNetCore.Http.Generated.GeneratedRouteBuilderExtensionsCore.MapCore(
|
|
|
+ endpoints,
|
|
|
+ pattern,
|
|
|
+ handler,
|
|
|
+ GetVerb,
|
|
|
+ filePath,
|
|
|
+ lineNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+namespace Microsoft.AspNetCore.Http.Generated
|
|
|
+{
|
|
|
+ using System;
|
|
|
+ using System.Collections;
|
|
|
+ using System.Collections.Generic;
|
|
|
+ using System.Collections.ObjectModel;
|
|
|
+ using System.Diagnostics;
|
|
|
+ using System.Linq;
|
|
|
+ using System.Reflection;
|
|
|
+ using System.Threading.Tasks;
|
|
|
+ using System.IO;
|
|
|
+ using Microsoft.AspNetCore.Routing;
|
|
|
+ using Microsoft.AspNetCore.Routing.Patterns;
|
|
|
+ using Microsoft.AspNetCore.Builder;
|
|
|
+ using Microsoft.AspNetCore.Http;
|
|
|
+ using Microsoft.AspNetCore.Http.Metadata;
|
|
|
+ using Microsoft.Extensions.DependencyInjection;
|
|
|
+ using Microsoft.Extensions.FileProviders;
|
|
|
+ using Microsoft.Extensions.Primitives;
|
|
|
+
|
|
|
+ using MetadataPopulator = System.Func<System.Reflection.MethodInfo, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions?, Microsoft.AspNetCore.Http.RequestDelegateMetadataResult>;
|
|
|
+ using RequestDelegateFactoryFunc = System.Func<System.Delegate, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions, Microsoft.AspNetCore.Http.RequestDelegateMetadataResult?, Microsoft.AspNetCore.Http.RequestDelegateResult>;
|
|
|
+
|
|
|
+ file static class GeneratedRouteBuilderExtensionsCore
|
|
|
+ {
|
|
|
+
|
|
|
+ private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new()
|
|
|
+ {
|
|
|
+ [(@"TestMapActions.cs", 15)] = (
|
|
|
+ (methodInfo, options) =>
|
|
|
+ {
|
|
|
+ Debug.Assert(options?.EndpointBuilder != null, "EndpointBuilder not found.");
|
|
|
+ options.EndpointBuilder.Metadata.Add(new SourceKey(@"TestMapActions.cs", 15));
|
|
|
+ return new RequestDelegateMetadataResult { EndpointMetadata = options.EndpointBuilder.Metadata.AsReadOnly() };
|
|
|
+ },
|
|
|
+ (del, options, inferredMetadataResult) =>
|
|
|
+ {
|
|
|
+ var handler = (System.Func<string, string, string>)del;
|
|
|
+ EndpointFilterDelegate? filteredInvocation = null;
|
|
|
+
|
|
|
+ if (options?.EndpointBuilder?.FilterFactories.Count > 0)
|
|
|
+ {
|
|
|
+ filteredInvocation = GeneratedRouteBuilderExtensionsCore.BuildFilterDelegate(ic =>
|
|
|
+ {
|
|
|
+ if (ic.HttpContext.Response.StatusCode == 400)
|
|
|
+ {
|
|
|
+ return ValueTask.FromResult<object?>(Results.Empty);
|
|
|
+ }
|
|
|
+ return ValueTask.FromResult<object?>(handler(ic.GetArgument<string>(0), ic.GetArgument<string>(1)));
|
|
|
+ },
|
|
|
+ options.EndpointBuilder,
|
|
|
+ handler.Method);
|
|
|
+ }
|
|
|
+
|
|
|
+ Task RequestHandler(HttpContext httpContext)
|
|
|
+ {
|
|
|
+ // Endpoint Parameter: p1 (Type = string, IsOptional = False, Source = Query)
|
|
|
+ var p1_raw = httpContext.Request.Query["p1"];
|
|
|
+ if (StringValues.IsNullOrEmpty(p1_raw))
|
|
|
+ {
|
|
|
+ httpContext.Response.StatusCode = 400;
|
|
|
+ return Task.CompletedTask;
|
|
|
+ }
|
|
|
+ var p1_local = p1_raw.ToString();
|
|
|
+
|
|
|
+ // Endpoint Parameter: p2 (Type = string, IsOptional = False, Source = Query)
|
|
|
+ var p2_raw = httpContext.Request.Query["p2"];
|
|
|
+ if (StringValues.IsNullOrEmpty(p2_raw))
|
|
|
+ {
|
|
|
+ httpContext.Response.StatusCode = 400;
|
|
|
+ return Task.CompletedTask;
|
|
|
+ }
|
|
|
+ var p2_local = p2_raw.ToString();
|
|
|
+
|
|
|
+ httpContext.Response.ContentType ??= "text/plain";
|
|
|
+ var result = handler(p1_local, p2_local);
|
|
|
+ return httpContext.Response.WriteAsync(result);
|
|
|
+ }
|
|
|
+ async Task RequestHandlerFiltered(HttpContext httpContext)
|
|
|
+ {
|
|
|
+ var result = await filteredInvocation(new DefaultEndpointFilterInvocationContext(httpContext));
|
|
|
+ await GeneratedRouteBuilderExtensionsCore.ExecuteObjectResult(result, httpContext);
|
|
|
+ }
|
|
|
+
|
|
|
+ RequestDelegate targetDelegate = filteredInvocation is null ? RequestHandler : RequestHandlerFiltered;
|
|
|
+ var metadata = inferredMetadataResult?.EndpointMetadata ?? ReadOnlyCollection<object>.Empty;
|
|
|
+ return new RequestDelegateResult(targetDelegate, metadata);
|
|
|
+ }),
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ internal static RouteHandlerBuilder MapCore(
|
|
|
+ this IEndpointRouteBuilder routes,
|
|
|
+ string pattern,
|
|
|
+ Delegate handler,
|
|
|
+ IEnumerable<string> 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|