@@ -500,7 +500,7 @@ public override bool IsDefined(Type attributeType, bool inherit)
500
500
}
501
501
""" ;
502
502
503
- public static string GetGeneratedRouteBuilderExtensionsSource ( string genericThunks , string thunks , string endpoints , string helperMethods , string helperTypes ) => $$ """
503
+ public static string GetGeneratedRouteBuilderExtensionsSource ( string endpoints , string helperMethods , string helperTypes ) => $$ """
504
504
{{ SourceHeader }}
505
505
506
506
namespace Microsoft.AspNetCore.Builder
@@ -517,8 +517,18 @@ public SourceKey(string path, int line)
517
517
Line = line;
518
518
}
519
519
}
520
+ }
520
521
521
- {{ GetEndpoints ( endpoints ) }}
522
+ namespace System.Runtime.CompilerServices
523
+ {
524
+ {{ GeneratedCodeAttribute }}
525
+ [AttributeUsage(AttributeTargets.Method)]
526
+ file sealed class InterceptsLocationAttribute : Attribute
527
+ {
528
+ public InterceptsLocationAttribute(string filePath, int line, int column)
529
+ {
530
+ }
531
+ }
522
532
}
523
533
524
534
namespace Microsoft.AspNetCore.Http.Generated
@@ -554,8 +564,29 @@ namespace Microsoft.AspNetCore.Http.Generated
554
564
{{ GeneratedCodeAttribute }}
555
565
file static class GeneratedRouteBuilderExtensionsCore
556
566
{
557
- {{ GetGenericThunks ( genericThunks ) }}
558
- {{ GetThunks ( thunks ) }}
567
+ private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get };
568
+ private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post };
569
+ private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put };
570
+ private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete };
571
+ private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch };
572
+
573
+ {{ endpoints }}
574
+
575
+ internal static RouteHandlerBuilder MapCore(
576
+ this IEndpointRouteBuilder routes,
577
+ string pattern,
578
+ Delegate handler,
579
+ IEnumerable<string>? httpMethods,
580
+ MetadataPopulator populateMetadata,
581
+ RequestDelegateFactoryFunc createRequestDelegate)
582
+ {
583
+ return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate);
584
+ }
585
+
586
+ private static T Cast<T>(Delegate d, T _) where T : Delegate
587
+ {
588
+ return (T)d;
589
+ }
559
590
560
591
private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi)
561
592
{
@@ -600,63 +631,4 @@ private static Task ExecuteObjectResult(object? obj, HttpContext httpContext)
600
631
{{ LogOrThrowExceptionHelperClass }}
601
632
}
602
633
""" ;
603
- private static string GetGenericThunks ( string genericThunks ) => genericThunks != string . Empty ? $$ """
604
- private static class GenericThunks<T>
605
- {
606
- public static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new()
607
- {
608
- {{ genericThunks }}
609
- };
610
- }
611
-
612
- internal static RouteHandlerBuilder MapCore<T>(
613
- this IEndpointRouteBuilder routes,
614
- string pattern,
615
- Delegate handler,
616
- IEnumerable<string> httpMethods,
617
- string filePath,
618
- int lineNumber)
619
- {
620
- var (populateMetadata, createRequestDelegate) = GenericThunks<T>.map[(filePath, lineNumber)];
621
- return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate);
622
- }
623
- """ : string . Empty ;
624
-
625
- private static string GetThunks ( string thunks ) => thunks != string . Empty ? $$ """
626
- private static readonly Dictionary<(string, int), (MetadataPopulator, RequestDelegateFactoryFunc)> map = new()
627
- {
628
- {{ thunks }}
629
- };
630
-
631
- internal static RouteHandlerBuilder MapCore(
632
- this IEndpointRouteBuilder routes,
633
- string pattern,
634
- Delegate handler,
635
- IEnumerable<string>? httpMethods,
636
- string filePath,
637
- int lineNumber)
638
- {
639
- var (populateMetadata, createRequestDelegate) = map[(filePath, lineNumber)];
640
- return RouteHandlerServices.Map(routes, pattern, handler, httpMethods, populateMetadata, createRequestDelegate);
641
- }
642
- """ : string . Empty ;
643
-
644
- private static string GetEndpoints ( string endpoints ) => endpoints != string . Empty ? $$ """
645
- // This class needs to be internal so that the compiled application
646
- // has access to the strongly-typed endpoint definitions that are
647
- // generated by the compiler so that they will be favored by
648
- // overload resolution and opt the runtime in to the code generated
649
- // implementation produced here.
650
- {{ GeneratedCodeAttribute }}
651
- internal static class GenerateRouteBuilderEndpoints
652
- {
653
- private static readonly string[] GetVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Get };
654
- private static readonly string[] PostVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Post };
655
- private static readonly string[] PutVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Put };
656
- private static readonly string[] DeleteVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Delete };
657
- private static readonly string[] PatchVerb = new[] { global::Microsoft.AspNetCore.Http.HttpMethods.Patch };
658
-
659
- {{ endpoints }}
660
- }
661
- """ : string . Empty ;
662
634
}
0 commit comments