Skip to content

Commit 709c0d8

Browse files
committed
Update RDG to use interceptors feature
1 parent 4be2661 commit 709c0d8

File tree

64 files changed

+6654
-6589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+6654
-6589
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1414
<AnalysisLevel>latest</AnalysisLevel>
1515
<AnalysisMode>Default</AnalysisMode>
16+
<RestoreAdditionalProjectSources>/Users/captainsafia/repos/roslyn/artifacts/packages/Release/Shipping</RestoreAdditionalProjectSources>
1617
</PropertyGroup>
1718

1819
<!-- Defines project type conventions. -->

eng/Versions.props

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@
136136
<MicrosoftEntityFrameworkCoreVersion>8.0.0-preview.5.23268.2</MicrosoftEntityFrameworkCoreVersion>
137137
<MicrosoftEntityFrameworkCoreDesignVersion>8.0.0-preview.5.23268.2</MicrosoftEntityFrameworkCoreDesignVersion>
138138
<!-- Packages from dotnet/roslyn -->
139-
<MicrosoftCodeAnalysisCommonVersion>4.4.0-4.22520.2</MicrosoftCodeAnalysisCommonVersion>
140-
<MicrosoftCodeAnalysisExternalAccessAspNetCoreVersion>4.4.0-4.22520.2</MicrosoftCodeAnalysisExternalAccessAspNetCoreVersion>
141-
<MicrosoftCodeAnalysisCSharpVersion>4.4.0-4.22520.2</MicrosoftCodeAnalysisCSharpVersion>
142-
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.4.0-4.22520.2</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
139+
<MicrosoftCodeAnalysisCommonVersion>4.7.0-dev</MicrosoftCodeAnalysisCommonVersion>
140+
<MicrosoftCodeAnalysisExternalAccessAspNetCoreVersion>4.7.0-dev</MicrosoftCodeAnalysisExternalAccessAspNetCoreVersion>
141+
<MicrosoftCodeAnalysisCSharpVersion>4.7.0-dev</MicrosoftCodeAnalysisCSharpVersion>
142+
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.7.0-dev</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
143143
<!-- Packages from NuGet/Nuget.client -->
144144
<!-- If you update these versions, make sure to also update https://github.com/dotnet/aspnetcore/blob/main/eng/SourceBuildPrebuiltBaseline.xml -->
145145
<NuGetPackagingVersion>6.2.2</NuGetPackagingVersion>
@@ -231,11 +231,13 @@
231231
<Analyzer_MicrosoftCodeAnalysisCSharpWorkspacesVersion>3.3.1</Analyzer_MicrosoftCodeAnalysisCSharpWorkspacesVersion>
232232
<!-- Pin the version of the M.CA dependencies that we utilize with a cutom version property $(MicrosoftCodeAnalysisVersion_LatestVS) to avoid automatically
233233
consuming the newest version of the packages when using the $(MicrosoftCodeAnalysisCSharpVersion) properties in source-build. -->
234-
<MicrosoftCodeAnalysisVersion_LatestVS>4.5.0</MicrosoftCodeAnalysisVersion_LatestVS>
235-
<MicrosoftCodeAnalysisExternalAccessAspNetCoreVersion>4.4.0-4.22520.2</MicrosoftCodeAnalysisExternalAccessAspNetCoreVersion>
236-
<MicrosoftCodeAnalysisCommonVersion>4.4.0-4.22520.2</MicrosoftCodeAnalysisCommonVersion>
237-
<MicrosoftCodeAnalysisCSharpVersion>4.4.0-4.22520.2</MicrosoftCodeAnalysisCSharpVersion>
238-
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.4.0-4.22520.2</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
234+
<MicrosoftCodeAnalysisVersion_LatestVS>4.7.0-dev</MicrosoftCodeAnalysisVersion_LatestVS>
235+
<MicrosoftCodeAnalysisExternalAccessAspNetCoreVersion>4.7.0-dev</MicrosoftCodeAnalysisExternalAccessAspNetCoreVersion>
236+
<MicrosoftCodeAnalysisCommonVersion>4.7.0-dev</MicrosoftCodeAnalysisCommonVersion>
237+
<MicrosoftCodeAnalysisCSharpVersion>4.7.0-dev</MicrosoftCodeAnalysisCSharpVersion>
238+
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.7.0-dev</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
239+
<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
240+
<MicrosoftNetCompilersToolsetVersion>4.7.0-dev</MicrosoftNetCompilersToolsetVersion>
239241
<MicrosoftCodeAnalysisPublicApiAnalyzersVersion>3.3.3</MicrosoftCodeAnalysisPublicApiAnalyzersVersion>
240242
<MicrosoftCodeAnalysisCSharpAnalyzerTestingXUnitVersion>1.1.2-beta1.22531.1</MicrosoftCodeAnalysisCSharpAnalyzerTestingXUnitVersion>
241243
<MicrosoftCodeAnalysisCSharpCodeFixTestingXUnitVersion>1.1.2-beta1.22531.1</MicrosoftCodeAnalysisCSharpCodeFixTestingXUnitVersion>

src/Http/Http.Extensions/gen/GeneratorSteps.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator;
55
internal class GeneratorSteps
66
{
77
internal const string EndpointModelStep = nameof(EndpointModelStep);
8-
internal const string EndpointsWithoutDiagnosicsStep = nameof(EndpointsWithoutDiagnosicsStep);
8+
internal const string EndpointsWithoutDiagnosticsStep = nameof(EndpointsWithoutDiagnosticsStep);
9+
internal const string EndpointsInterceptorsStep = nameof(EndpointsInterceptorsStep);
10+
internal const string EndpointsHelperMethodsStep = nameof(EndpointsHelperMethodsStep);
11+
internal const string EndpointsHelperTypesStep = nameof(EndpointsHelperTypesStep);
912
}

src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs

Lines changed: 105 additions & 119 deletions
Large diffs are not rendered by default.

src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs

Lines changed: 35 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public override bool IsDefined(Type attributeType, bool inherit)
496496
}
497497
""";
498498

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) => $$"""
500500
{{SourceHeader}}
501501
502502
namespace Microsoft.AspNetCore.Builder
@@ -513,8 +513,18 @@ public SourceKey(string path, int line)
513513
Line = line;
514514
}
515515
}
516+
}
516517
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+
}
518528
}
519529
520530
namespace Microsoft.AspNetCore.Http.Generated
@@ -549,8 +559,29 @@ namespace Microsoft.AspNetCore.Http.Generated
549559
550560
file static class GeneratedRouteBuilderExtensionsCore
551561
{
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+
}
554585
555586
private static EndpointFilterDelegate BuildFilterDelegate(EndpointFilterDelegate filteredInvocation, EndpointBuilder builder, MethodInfo mi)
556587
{
@@ -595,63 +626,4 @@ private static Task ExecuteObjectResult(object? obj, HttpContext httpContext)
595626
{{LogOrThrowExceptionHelperClass}}
596627
}
597628
""";
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;
657629
}

src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterConstants.cs renamed to src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
using Microsoft.CodeAnalysis;
4-
namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters;
4+
5+
namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters;
56

67
internal static class EmitterConstants
78
{

src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterContext.cs renamed to src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
3-
namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel.Emitters;
3+
4+
namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters;
45

56
internal sealed class EmitterContext
67
{

src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EmitterExtensions.cs renamed to src/Http/Http.Extensions/gen/StaticRouteHandler/Emitters/EmitterExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
using System;
44
using System.Diagnostics.CodeAnalysis;
55
using Microsoft.AspNetCore.Analyzers.Infrastructure;
6+
using Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Model;
67
using Microsoft.CodeAnalysis;
78

8-
namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandlerModel;
9+
namespace Microsoft.AspNetCore.Http.RequestDelegateGenerator.StaticRouteHandler.Emitters;
910

1011
internal static class EmitterExtensions
1112
{

0 commit comments

Comments
 (0)