Skip to content

Commit e2494f1

Browse files
committed
[AOT] Enable analysis and annotate Http.Results
1 parent a527ac5 commit e2494f1

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
@@ -152,7 +152,9 @@ Microsoft.AspNetCore.Http.HttpResults.Utf8ContentHttpResult.ExecuteAsync(Microso
152152
Microsoft.AspNetCore.Http.HttpResults.Utf8ContentHttpResult.ResponseContent.get -> System.ReadOnlyMemory<byte>
153153
Microsoft.AspNetCore.Http.HttpResults.Utf8ContentHttpResult.StatusCode.get -> int?
154154
static Microsoft.AspNetCore.Http.Results.Accepted<TValue>(string? uri = null, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
155+
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, object? value = null) -> Microsoft.AspNetCore.Http.IResult!
155156
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute<TValue>(string? routeName = null, object? routeValues = null, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
157+
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute<TValue>(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
156158
static Microsoft.AspNetCore.Http.Results.BadRequest<TValue>(TValue? error) -> Microsoft.AspNetCore.Http.IResult!
157159
static Microsoft.AspNetCore.Http.Results.Conflict<TValue>(TValue? error) -> Microsoft.AspNetCore.Http.IResult!
158160
static Microsoft.AspNetCore.Http.Results.Content(string? content, Microsoft.Net.Http.Headers.MediaTypeHeaderValue! contentType) -> Microsoft.AspNetCore.Http.IResult!
@@ -166,21 +168,29 @@ static Microsoft.AspNetCore.Http.Results.Created(string? uri, object? value) ->
166168
static Microsoft.AspNetCore.Http.Results.Created(System.Uri? uri, object? value) -> Microsoft.AspNetCore.Http.IResult!
167169
static Microsoft.AspNetCore.Http.Results.Created<TValue>(string? uri, TValue? value) -> Microsoft.AspNetCore.Http.IResult!
168170
static Microsoft.AspNetCore.Http.Results.Created<TValue>(System.Uri? uri, TValue? value) -> Microsoft.AspNetCore.Http.IResult!
171+
static Microsoft.AspNetCore.Http.Results.CreatedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, object? value = null) -> Microsoft.AspNetCore.Http.IResult!
169172
static Microsoft.AspNetCore.Http.Results.CreatedAtRoute<TValue>(string? routeName = null, object? routeValues = null, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
173+
static Microsoft.AspNetCore.Http.Results.CreatedAtRoute<TValue>(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
170174
static Microsoft.AspNetCore.Http.Results.Json<TValue>(TValue? data, System.Text.Json.JsonSerializerOptions? options = null, string? contentType = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.IResult!
171175
static Microsoft.AspNetCore.Http.Results.NotFound<TValue>(TValue? value) -> Microsoft.AspNetCore.Http.IResult!
172176
static Microsoft.AspNetCore.Http.Results.Ok<TValue>(TValue? value) -> Microsoft.AspNetCore.Http.IResult!
177+
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!
173178
static Microsoft.AspNetCore.Http.Results.Text(string? content, string? contentType = null, System.Text.Encoding? contentEncoding = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.IResult!
174179
static Microsoft.AspNetCore.Http.Results.Text(string? content, string? contentType, System.Text.Encoding? contentEncoding) -> Microsoft.AspNetCore.Http.IResult!
175180
static Microsoft.AspNetCore.Http.Results.Text(System.ReadOnlySpan<byte> utf8Content, string? contentType = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.IResult!
176181
static Microsoft.AspNetCore.Http.Results.UnprocessableEntity<TValue>(TValue? error) -> Microsoft.AspNetCore.Http.IResult!
182+
static Microsoft.AspNetCore.Http.TypedResults.AcceptedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.AcceptedAtRoute!
183+
static Microsoft.AspNetCore.Http.TypedResults.AcceptedAtRoute<TValue>(TValue? value, string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.AcceptedAtRoute<TValue>!
177184
static Microsoft.AspNetCore.Http.TypedResults.Content(string? content, string? contentType = null, System.Text.Encoding? contentEncoding = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.HttpResults.ContentHttpResult!
178185
static Microsoft.AspNetCore.Http.TypedResults.Content(string? content, string? contentType, System.Text.Encoding? contentEncoding) -> Microsoft.AspNetCore.Http.HttpResults.ContentHttpResult!
179186
static Microsoft.AspNetCore.Http.TypedResults.Created() -> Microsoft.AspNetCore.Http.HttpResults.Created!
180187
static Microsoft.AspNetCore.Http.TypedResults.Created(string? uri) -> Microsoft.AspNetCore.Http.HttpResults.Created!
181188
static Microsoft.AspNetCore.Http.TypedResults.Created(System.Uri? uri) -> Microsoft.AspNetCore.Http.HttpResults.Created!
182189
static Microsoft.AspNetCore.Http.TypedResults.Created<TValue>(string? uri, TValue? value) -> Microsoft.AspNetCore.Http.HttpResults.Created<TValue>!
183190
static Microsoft.AspNetCore.Http.TypedResults.Created<TValue>(System.Uri? uri, TValue? value) -> Microsoft.AspNetCore.Http.HttpResults.Created<TValue>!
191+
static Microsoft.AspNetCore.Http.TypedResults.CreatedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute!
192+
static Microsoft.AspNetCore.Http.TypedResults.CreatedAtRoute<TValue>(TValue? value, string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute<TValue>!
193+
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!
184194
static Microsoft.AspNetCore.Http.TypedResults.Text(string? content, string? contentType = null, System.Text.Encoding? contentEncoding = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.HttpResults.ContentHttpResult!
185195
static Microsoft.AspNetCore.Http.TypedResults.Text(string? content, string? contentType, System.Text.Encoding? contentEncoding) -> Microsoft.AspNetCore.Http.HttpResults.ContentHttpResult!
186196
static Microsoft.AspNetCore.Http.TypedResults.Text(System.ReadOnlySpan<byte> utf8Content, string? contentType = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.HttpResults.Utf8ContentHttpResult!

0 commit comments

Comments
 (0)