Skip to content

Remove RequiresUnreferencedCode from low-level endpoint map methods #42519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Http/HttpAbstractions.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"solution": {
"path": "..\\..\\AspNetCore.sln",
"projects": [
"src\\DataProtection\\Abstractions\\src\\Microsoft.AspNetCore.DataProtection.Abstractions.csproj",
"src\\DataProtection\\Cryptography.Internal\\src\\Microsoft.AspNetCore.Cryptography.Internal.csproj",
"src\\DataProtection\\DataProtection\\src\\Microsoft.AspNetCore.DataProtection.csproj",
"src\\DefaultBuilder\\src\\Microsoft.AspNetCore.csproj",
"src\\Extensions\\Features\\src\\Microsoft.Extensions.Features.csproj",
"src\\Extensions\\Features\\test\\Microsoft.Extensions.Features.Tests.csproj",
"src\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj",
Expand Down Expand Up @@ -43,15 +47,25 @@
"src\\Http\\samples\\MinimalSample\\MinimalSample.csproj",
"src\\Http\\samples\\SampleApp\\HttpAbstractions.SampleApp.csproj",
"src\\Middleware\\CORS\\src\\Microsoft.AspNetCore.Cors.csproj",
"src\\Middleware\\Diagnostics.Abstractions\\src\\Microsoft.AspNetCore.Diagnostics.Abstractions.csproj",
"src\\Middleware\\Diagnostics\\src\\Microsoft.AspNetCore.Diagnostics.csproj",
"src\\Middleware\\HostFiltering\\src\\Microsoft.AspNetCore.HostFiltering.csproj",
"src\\Middleware\\HttpOverrides\\src\\Microsoft.AspNetCore.HttpOverrides.csproj",
"src\\Middleware\\OutputCaching\\src\\Microsoft.AspNetCore.OutputCaching.csproj",
"src\\Middleware\\ResponseCaching.Abstractions\\src\\Microsoft.AspNetCore.ResponseCaching.Abstractions.csproj",
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj",
"src\\Mvc\\Mvc.Abstractions\\src\\Microsoft.AspNetCore.Mvc.Abstractions.csproj",
"src\\Mvc\\Mvc.Core\\src\\Microsoft.AspNetCore.Mvc.Core.csproj",
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj",
"src\\Security\\Authentication\\Core\\src\\Microsoft.AspNetCore.Authentication.csproj",
"src\\Security\\Authorization\\Core\\src\\Microsoft.AspNetCore.Authorization.csproj",
"src\\Security\\Authorization\\Policy\\src\\Microsoft.AspNetCore.Authorization.Policy.csproj",
"src\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj",
"src\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj",
"src\\Servers\\IIS\\IIS\\src\\Microsoft.AspNetCore.Server.IIS.csproj",
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj",
"src\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj",
"src\\Servers\\Kestrel\\Transport.Quic\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj",
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj",
"src\\Testing\\src\\Microsoft.AspNetCore.Testing.csproj",
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj"
Expand Down
14 changes: 0 additions & 14 deletions src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static RouteGroupBuilder MapGroup(this IEndpointRouteBuilder endpoints, R
/// <param name="pattern">The route pattern.</param>
/// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
[RequiresUnreferencedCode(MapEndpointTrimmerWarning)]
public static IEndpointConventionBuilder MapGet(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string pattern,
Expand All @@ -80,7 +79,6 @@ public static IEndpointConventionBuilder MapGet(
/// <param name="pattern">The route pattern.</param>
/// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
[RequiresUnreferencedCode(MapEndpointTrimmerWarning)]
public static IEndpointConventionBuilder MapPost(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string pattern,
Expand All @@ -97,7 +95,6 @@ public static IEndpointConventionBuilder MapPost(
/// <param name="pattern">The route pattern.</param>
/// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
[RequiresUnreferencedCode(MapEndpointTrimmerWarning)]
public static IEndpointConventionBuilder MapPut(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string pattern,
Expand All @@ -114,7 +111,6 @@ public static IEndpointConventionBuilder MapPut(
/// <param name="pattern">The route pattern.</param>
/// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
[RequiresUnreferencedCode(MapEndpointTrimmerWarning)]
public static IEndpointConventionBuilder MapDelete(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string pattern,
Expand All @@ -131,7 +127,6 @@ public static IEndpointConventionBuilder MapDelete(
/// <param name="pattern">The route pattern.</param>
/// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
[RequiresUnreferencedCode(MapEndpointTrimmerWarning)]
public static IEndpointConventionBuilder MapPatch(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string pattern,
Expand All @@ -149,7 +144,6 @@ public static IEndpointConventionBuilder MapPatch(
/// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
/// <param name="httpMethods">HTTP methods that the endpoint will match.</param>
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
[RequiresUnreferencedCode(MapEndpointTrimmerWarning)]
public static IEndpointConventionBuilder MapMethods(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string pattern,
Expand All @@ -172,7 +166,6 @@ public static IEndpointConventionBuilder MapMethods(
/// <param name="pattern">The route pattern.</param>
/// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
[RequiresUnreferencedCode(MapEndpointTrimmerWarning)]
public static IEndpointConventionBuilder Map(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string pattern,
Expand All @@ -189,7 +182,6 @@ public static IEndpointConventionBuilder Map(
/// <param name="pattern">The route pattern.</param>
/// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
[RequiresUnreferencedCode(MapEndpointTrimmerWarning)]
public static IEndpointConventionBuilder Map(
this IEndpointRouteBuilder endpoints,
RoutePattern pattern,
Expand All @@ -199,12 +191,6 @@ public static IEndpointConventionBuilder Map(
ArgumentNullException.ThrowIfNull(pattern);
ArgumentNullException.ThrowIfNull(requestDelegate);

var returnType = requestDelegate.Method.ReturnType;
if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>))
{
return Map(endpoints, pattern, requestDelegate as Delegate);
}

const int defaultOrder = 0;

var builder = new RouteEndpointBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ public static object[][] MapMethods
{
get
{
IEndpointConventionBuilder MapGet(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
IEndpointConventionBuilder MapGet(IEndpointRouteBuilder routes, string template, Delegate action) =>
routes.MapGet(template, action);

IEndpointConventionBuilder MapPost(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
IEndpointConventionBuilder MapPost(IEndpointRouteBuilder routes, string template, Delegate action) =>
routes.MapPost(template, action);

IEndpointConventionBuilder MapPut(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
IEndpointConventionBuilder MapPut(IEndpointRouteBuilder routes, string template, Delegate action) =>
routes.MapPut(template, action);

IEndpointConventionBuilder MapDelete(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
IEndpointConventionBuilder MapDelete(IEndpointRouteBuilder routes, string template, Delegate action) =>
routes.MapDelete(template, action);

IEndpointConventionBuilder Map(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
IEndpointConventionBuilder Map(IEndpointRouteBuilder routes, string template, Delegate action) =>
routes.Map(template, action);

return new object[][]
{
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)MapGet },
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)MapPost },
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)MapPut },
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)MapDelete },
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)Map },
new object[] { (Func<IEndpointRouteBuilder, string, Delegate, IEndpointConventionBuilder>)MapGet },
new object[] { (Func<IEndpointRouteBuilder, string, Delegate, IEndpointConventionBuilder>)MapPost },
new object[] { (Func<IEndpointRouteBuilder, string, Delegate, IEndpointConventionBuilder>)MapPut },
new object[] { (Func<IEndpointRouteBuilder, string, Delegate, IEndpointConventionBuilder>)MapDelete },
new object[] { (Func<IEndpointRouteBuilder, string, Delegate, IEndpointConventionBuilder>)Map },
};
}
}
Expand All @@ -81,7 +81,7 @@ public void MapEndpoint_StringPattern_BuildsEndpoint()

[Theory]
[MemberData(nameof(MapMethods))]
public async Task MapEndpoint_ReturnGenericTypeTask_GeneratedDelegate(Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder> map)
public async Task MapEndpoint_ReturnGenericTypeTask_GeneratedDelegate(Func<IEndpointRouteBuilder, string, Delegate, IEndpointConventionBuilder> map)
{
var httpContext = new DefaultHttpContext();
var responseBodyStream = new MemoryStream();
Expand Down