Skip to content

Commit 4022f3d

Browse files
committed
[AOT] Enable analysis and annotate Http.Results
1 parent 6f1752a commit 4022f3d

17 files changed

+436
-34
lines changed

eng/TrimmableProjects.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<TrimmableProject Include="Microsoft.AspNetCore.Http.Abstractions" />
2626
<TrimmableProject Include="Microsoft.AspNetCore.Http.Extensions" />
2727
<TrimmableProject Include="Microsoft.AspNetCore.Http.Features" />
28+
<TrimmableProject Include="Microsoft.AspNetCore.Http.Results" />
2829
<TrimmableProject Include="Microsoft.AspNetCore.Http" />
2930
<TrimmableProject Include="Microsoft.AspNetCore.Metadata" />
3031
<TrimmableProject Include="Microsoft.AspNetCore.Routing.Abstractions" />

src/Http/Http.Results/src/AcceptedAtRoute.cs

Lines changed: 16 additions & 2 deletions
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.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Reflection;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Http.Metadata;
@@ -22,11 +23,24 @@ public sealed class AcceptedAtRoute : IResult, IEndpointMetadataProvider, IStatu
2223
/// provided.
2324
/// </summary>
2425
/// <param name="routeValues">The route data to use for generating the URL.</param>
26+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
2527
internal AcceptedAtRoute(object? routeValues)
2628
: this(routeName: null, routeValues: routeValues)
2729
{
2830
}
2931

32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="AcceptedAtRoute"/> class with the values
34+
/// provided.
35+
/// </summary>
36+
/// <param name="routeName">The name of the route to use for generating the URL.</param>
37+
/// <param name="routeValues">The route data to use for generating the URL.</param>
38+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
39+
internal AcceptedAtRoute(string? routeName, object? routeValues)
40+
: this(routeName, new RouteValueDictionary(routeValues))
41+
{
42+
}
43+
3044
/// <summary>
3145
/// Initializes a new instance of the <see cref="AcceptedAtRoute"/> class with the values
3246
/// provided.
@@ -35,10 +49,10 @@ internal AcceptedAtRoute(object? routeValues)
3549
/// <param name="routeValues">The route data to use for generating the URL.</param>
3650
internal AcceptedAtRoute(
3751
string? routeName,
38-
object? routeValues)
52+
RouteValueDictionary routeValues)
3953
{
4054
RouteName = routeName;
41-
RouteValues = new RouteValueDictionary(routeValues);
55+
RouteValues = routeValues;
4256
}
4357

4458
/// <summary>

src/Http/Http.Results/src/AcceptedAtRouteOfT.cs

Lines changed: 17 additions & 2 deletions
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.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Reflection;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Http.Metadata;
@@ -24,11 +25,25 @@ public sealed class AcceptedAtRoute<TValue> : IResult, IEndpointMetadataProvider
2425
/// </summary>
2526
/// <param name="routeValues">The route data to use for generating the URL.</param>
2627
/// <param name="value">The value to format in the entity body.</param>
28+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
2729
internal AcceptedAtRoute(object? routeValues, TValue? value)
2830
: this(routeName: null, routeValues: routeValues, value: value)
2931
{
3032
}
3133

34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="AcceptedAtRoute"/> class with the values
36+
/// provided.
37+
/// </summary>
38+
/// <param name="routeName">The name of the route to use for generating the URL.</param>
39+
/// <param name="routeValues">The route data to use for generating the URL.</param>
40+
/// <param name="value">The value to format in the entity body.</param>
41+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
42+
internal AcceptedAtRoute(string? routeName, object? routeValues, TValue? value)
43+
: this(routeName, new RouteValueDictionary(routeValues), value)
44+
{
45+
}
46+
3247
/// <summary>
3348
/// Initializes a new instance of the <see cref="AcceptedAtRoute"/> class with the values
3449
/// provided.
@@ -38,12 +53,12 @@ internal AcceptedAtRoute(object? routeValues, TValue? value)
3853
/// <param name="value">The value to format in the entity body.</param>
3954
internal AcceptedAtRoute(
4055
string? routeName,
41-
object? routeValues,
56+
RouteValueDictionary routeValues,
4257
TValue? value)
4358
{
4459
Value = value;
4560
RouteName = routeName;
46-
RouteValues = new RouteValueDictionary(routeValues);
61+
RouteValues = routeValues;
4762
HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);
4863
}
4964

src/Http/Http.Results/src/CreatedAtRoute.cs

Lines changed: 16 additions & 2 deletions
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.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Reflection;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Http.Metadata;
@@ -22,11 +23,24 @@ public sealed class CreatedAtRoute : IResult, IEndpointMetadataProvider, IStatus
2223
/// provided.
2324
/// </summary>
2425
/// <param name="routeValues">The route data to use for generating the URL.</param>
26+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
2527
internal CreatedAtRoute(object? routeValues)
2628
: this(routeName: null, routeValues: routeValues)
2729
{
2830
}
2931

32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="CreatedAtRoute"/> class with the values
34+
/// provided.
35+
/// </summary>
36+
/// <param name="routeName">The name of the route to use for generating the URL.</param>
37+
/// <param name="routeValues">The route data to use for generating the URL.</param>
38+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
39+
internal CreatedAtRoute(string? routeName, object? routeValues)
40+
: this(routeName, new RouteValueDictionary(routeValues))
41+
{
42+
}
43+
3044
/// <summary>
3145
/// Initializes a new instance of the <see cref="CreatedAtRoute"/> class with the values
3246
/// provided.
@@ -35,10 +49,10 @@ internal CreatedAtRoute(object? routeValues)
3549
/// <param name="routeValues">The route data to use for generating the URL.</param>
3650
internal CreatedAtRoute(
3751
string? routeName,
38-
object? routeValues)
52+
RouteValueDictionary routeValues)
3953
{
4054
RouteName = routeName;
41-
RouteValues = new RouteValueDictionary(routeValues);
55+
RouteValues = routeValues;
4256
}
4357

4458
/// <summary>

src/Http/Http.Results/src/CreatedAtRouteOfT.cs

Lines changed: 17 additions & 2 deletions
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.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Reflection;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Http.Metadata;
@@ -24,11 +25,25 @@ public sealed class CreatedAtRoute<TValue> : IResult, IEndpointMetadataProvider,
2425
/// </summary>
2526
/// <param name="routeValues">The route data to use for generating the URL.</param>
2627
/// <param name="value">The value to format in the entity body.</param>
28+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
2729
internal CreatedAtRoute(object? routeValues, TValue? value)
2830
: this(routeName: null, routeValues: routeValues, value: value)
2931
{
3032
}
3133

34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="CreatedAtRoute"/> class with the values
36+
/// provided.
37+
/// </summary>
38+
/// <param name="routeName">The name of the route to use for generating the URL.</param>
39+
/// <param name="routeValues">The route data to use for generating the URL.</param>
40+
/// <param name="value">The value to format in the entity body.</param>
41+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
42+
internal CreatedAtRoute(string? routeName, object? routeValues, TValue? value)
43+
: this(routeName, new RouteValueDictionary(routeValues), value)
44+
{
45+
}
46+
3247
/// <summary>
3348
/// Initializes a new instance of the <see cref="CreatedAtRoute"/> class with the values
3449
/// provided.
@@ -38,12 +53,12 @@ internal CreatedAtRoute(object? routeValues, TValue? value)
3853
/// <param name="value">The value to format in the entity body.</param>
3954
internal CreatedAtRoute(
4055
string? routeName,
41-
object? routeValues,
56+
RouteValueDictionary routeValues,
4257
TValue? value)
4358
{
4459
Value = value;
4560
RouteName = routeName;
46-
RouteValues = new RouteValueDictionary(routeValues);
61+
RouteValues = routeValues;
4762
HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);
4863
}
4964

src/Http/Http.Results/src/HttpResultsHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ public static Task WriteResultAsJsonAsync<T>(
3434

3535
// In this case the polymorphism is not
3636
// relevant and we don't need to box.
37+
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
38+
#pragma warning disable IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
3739
return httpContext.Response.WriteAsJsonAsync(
3840
value,
3941
options: jsonSerializerOptions,
4042
contentType: contentType);
43+
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
44+
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
4145
}
4246

4347
var runtimeType = value.GetType();
@@ -48,11 +52,15 @@ public static Task WriteResultAsJsonAsync<T>(
4852
// and avoid source generators issues.
4953
// https://github.com/dotnet/aspnetcore/issues/43894
5054
// https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-polymorphism
55+
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
56+
#pragma warning disable IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
5157
return httpContext.Response.WriteAsJsonAsync(
5258
value,
5359
runtimeType,
5460
options: jsonSerializerOptions,
5561
contentType: contentType);
62+
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
63+
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
5664
}
5765

5866
public static Task WriteResultAsContentAsync(

src/Http/Http.Results/src/Microsoft.AspNetCore.Http.Results.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<PackageTags>aspnetcore</PackageTags>
99
<IsPackable>false</IsPackable>
10-
<Nullable>enable</Nullable>
10+
<IsTrimmable>true</IsTrimmable>
1111
<RootNamespace>Microsoft.AspNetCore.Http.Result</RootNamespace>
1212
</PropertyGroup>
1313

src/Http/Http.Results/src/PublicAPI.Unshipped.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*REMOVED*static Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult!
55
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
66
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
7+
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, object? value = null) -> Microsoft.AspNetCore.Http.IResult!
8+
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute<TValue>(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
79
static Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult! (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
810
static Microsoft.AspNetCore.Http.Results.Created() -> Microsoft.AspNetCore.Http.IResult!
911
*REMOVED*static Microsoft.AspNetCore.Http.Results.Created(string! uri, object? value) -> Microsoft.AspNetCore.Http.IResult!
@@ -12,11 +14,19 @@ static Microsoft.AspNetCore.Http.Results.Created(string? uri, object? value) ->
1214
static Microsoft.AspNetCore.Http.Results.Created(System.Uri? uri, object? value) -> Microsoft.AspNetCore.Http.IResult!
1315
static Microsoft.AspNetCore.Http.Results.Created<TValue>(string? uri, TValue? value) -> Microsoft.AspNetCore.Http.IResult!
1416
static Microsoft.AspNetCore.Http.Results.Created<TValue>(System.Uri? uri, TValue? value) -> Microsoft.AspNetCore.Http.IResult!
17+
static Microsoft.AspNetCore.Http.Results.CreatedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, object? value = null) -> Microsoft.AspNetCore.Http.IResult!
18+
static Microsoft.AspNetCore.Http.Results.CreatedAtRoute<TValue>(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
19+
static Microsoft.AspNetCore.Http.Results.RedirectToRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary? routeValues, bool permanent = false, bool preserveMethod = false, string? fragment = null) -> Microsoft.AspNetCore.Http.IResult!
20+
static Microsoft.AspNetCore.Http.TypedResults.AcceptedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.AcceptedAtRoute!
21+
static Microsoft.AspNetCore.Http.TypedResults.AcceptedAtRoute<TValue>(TValue? value, string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.AcceptedAtRoute<TValue>!
1522
static Microsoft.AspNetCore.Http.TypedResults.Created() -> Microsoft.AspNetCore.Http.HttpResults.Created!
1623
static Microsoft.AspNetCore.Http.TypedResults.Created(string? uri) -> Microsoft.AspNetCore.Http.HttpResults.Created!
1724
static Microsoft.AspNetCore.Http.TypedResults.Created(System.Uri? uri) -> Microsoft.AspNetCore.Http.HttpResults.Created!
1825
static Microsoft.AspNetCore.Http.TypedResults.Created<TValue>(string? uri, TValue? value) -> Microsoft.AspNetCore.Http.HttpResults.Created<TValue>!
1926
static Microsoft.AspNetCore.Http.TypedResults.Created<TValue>(System.Uri? uri, TValue? value) -> Microsoft.AspNetCore.Http.HttpResults.Created<TValue>!
27+
static Microsoft.AspNetCore.Http.TypedResults.CreatedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute!
28+
static Microsoft.AspNetCore.Http.TypedResults.CreatedAtRoute<TValue>(TValue? value, string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute<TValue>!
29+
static Microsoft.AspNetCore.Http.TypedResults.RedirectToRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary? routeValues, bool permanent = false, bool preserveMethod = false, string? fragment = null) -> Microsoft.AspNetCore.Http.HttpResults.RedirectToRouteHttpResult!
2030
*REMOVED*static Microsoft.AspNetCore.Http.Results.Created<TValue>(System.Uri! uri, TValue? value) -> Microsoft.AspNetCore.Http.IResult!
2131
*REMOVED*static Microsoft.AspNetCore.Http.Results.Created<TValue>(string! uri, TValue? value) -> Microsoft.AspNetCore.Http.IResult!
2232
*REMOVED*static Microsoft.AspNetCore.Http.TypedResults.Created(System.Uri! uri) -> Microsoft.AspNetCore.Http.HttpResults.Created!

src/Http/Http.Results/src/RedirectToRouteHttpResult.cs

Lines changed: 32 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.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Microsoft.AspNetCore.Routing;
56
using Microsoft.Extensions.DependencyInjection;
67
using Microsoft.Extensions.Logging;
@@ -19,6 +20,7 @@ public sealed partial class RedirectToRouteHttpResult : IResult
1920
/// provided.
2021
/// </summary>
2122
/// <param name="routeValues">The parameters for the route.</param>
23+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
2224
internal RedirectToRouteHttpResult(object? routeValues)
2325
: this(routeName: null, routeValues: routeValues)
2426
{
@@ -30,6 +32,7 @@ internal RedirectToRouteHttpResult(object? routeValues)
3032
/// </summary>
3133
/// <param name="routeName">The name of the route.</param>
3234
/// <param name="routeValues">The parameters for the route.</param>
35+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
3336
internal RedirectToRouteHttpResult(
3437
string? routeName,
3538
object? routeValues)
@@ -45,6 +48,7 @@ internal RedirectToRouteHttpResult(
4548
/// <param name="routeValues">The parameters for the route.</param>
4649
/// <param name="permanent">If set to true, makes the redirect permanent (301).
4750
/// Otherwise a temporary redirect is used (302).</param>
51+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
4852
internal RedirectToRouteHttpResult(
4953
string? routeName,
5054
object? routeValues,
@@ -62,6 +66,7 @@ internal RedirectToRouteHttpResult(
6266
/// <param name="permanent">If set to true, makes the redirect permanent (301).
6367
/// Otherwise a temporary redirect is used (302).</param>
6468
/// <param name="fragment">The fragment to add to the URL.</param>
69+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
6570
internal RedirectToRouteHttpResult(
6671
string? routeName,
6772
object? routeValues,
@@ -82,15 +87,41 @@ internal RedirectToRouteHttpResult(
8287
/// <param name="preserveMethod">If set to true, make the temporary redirect (307)
8388
/// or permanent redirect (308) preserve the initial request method.</param>
8489
/// <param name="fragment">The fragment to add to the URL.</param>
90+
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
8591
internal RedirectToRouteHttpResult(
8692
string? routeName,
8793
object? routeValues,
8894
bool permanent,
8995
bool preserveMethod,
96+
string? fragment) : this(
97+
routeName,
98+
routeValues == null ? null : new RouteValueDictionary(routeValues),
99+
permanent,
100+
preserveMethod,
101+
fragment)
102+
{
103+
}
104+
105+
/// <summary>
106+
/// Initializes a new instance of the <see cref="RedirectToRouteHttpResult"/> with the values
107+
/// provided.
108+
/// </summary>
109+
/// <param name="routeName">The name of the route.</param>
110+
/// <param name="routeValues">The parameters for the route.</param>
111+
/// <param name="permanent">If set to true, makes the redirect permanent (301).
112+
/// Otherwise a temporary redirect is used (302).</param>
113+
/// <param name="preserveMethod">If set to true, make the temporary redirect (307)
114+
/// or permanent redirect (308) preserve the initial request method.</param>
115+
/// <param name="fragment">The fragment to add to the URL.</param>
116+
internal RedirectToRouteHttpResult(
117+
string? routeName,
118+
RouteValueDictionary? routeValues,
119+
bool permanent,
120+
bool preserveMethod,
90121
string? fragment)
91122
{
92123
RouteName = routeName;
93-
RouteValues = routeValues == null ? null : new RouteValueDictionary(routeValues);
124+
RouteValues = routeValues;
94125
PreserveMethod = preserveMethod;
95126
Permanent = permanent;
96127
Fragment = fragment;

0 commit comments

Comments
 (0)