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