Skip to content

Commit 13bc23b

Browse files
authored
Fix some trim warnings in Components.Endpoints (#49890)
- Add DynamicallyAccessedMembers attributes to places that flow Component Type around.
1 parent 28e5590 commit 13bc23b

18 files changed

+72
-26
lines changed

src/Components/Endpoints/src/Builder/ComponentTypeMetadata.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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;
5+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
6+
47
namespace Microsoft.AspNetCore.Components.Endpoints;
58

69
/// <summary>
@@ -12,13 +15,14 @@ public class ComponentTypeMetadata
1215
/// Initializes a new instance of <see cref="ComponentTypeMetadata"/>.
1316
/// </summary>
1417
/// <param name="componentType">The component type.</param>
15-
public ComponentTypeMetadata(Type componentType)
18+
public ComponentTypeMetadata([DynamicallyAccessedMembers(Component)] Type componentType)
1619
{
1720
Type = componentType;
1821
}
1922

2023
/// <summary>
2124
/// Gets the component type.
2225
/// </summary>
26+
[DynamicallyAccessedMembers(Component)]
2327
public Type Type { get; }
2428
}

src/Components/Endpoints/src/Builder/RazorComponentEndpointDataSource.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Linq;
67
using Microsoft.AspNetCore.Builder;
78
using Microsoft.AspNetCore.Components.Discovery;
89
using Microsoft.AspNetCore.Http;
910
using Microsoft.AspNetCore.Routing;
1011
using Microsoft.Extensions.Primitives;
12+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
1113

1214
namespace Microsoft.AspNetCore.Components.Endpoints;
1315

14-
internal class RazorComponentEndpointDataSource<TRootComponent> : EndpointDataSource
16+
internal class RazorComponentEndpointDataSource<[DynamicallyAccessedMembers(Component)] TRootComponent> : EndpointDataSource
1517
{
1618
private readonly object _lock = new();
1719
private readonly List<Action<EndpointBuilder>> _conventions = new();

src/Components/Endpoints/src/Builder/RazorComponentEndpointDataSourceFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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.Components.Discovery;
56
using Microsoft.AspNetCore.Components.Endpoints;
67
using Microsoft.AspNetCore.Routing;
8+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
79

810
namespace Microsoft.AspNetCore.Components.Infrastructure;
911

@@ -20,7 +22,7 @@ public RazorComponentEndpointDataSourceFactory(
2022
_providers = providers;
2123
}
2224

23-
public RazorComponentEndpointDataSource<TRootComponent> CreateDataSource<TRootComponent>(IEndpointRouteBuilder endpoints)
25+
public RazorComponentEndpointDataSource<TRootComponent> CreateDataSource<[DynamicallyAccessedMembers(Component)] TRootComponent>(IEndpointRouteBuilder endpoints)
2426
{
2527
var builder = ComponentApplicationBuilder.GetBuilder<TRootComponent>() ??
2628
DefaultRazorComponentApplication<TRootComponent>.Instance.GetBuilder();

src/Components/Endpoints/src/Builder/RazorComponentEndpointFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
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.Antiforgery;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Components.Discovery;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.AspNetCore.Routing;
910
using Microsoft.AspNetCore.Routing.Patterns;
1011
using Microsoft.Extensions.DependencyInjection;
12+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
1113

1214
namespace Microsoft.AspNetCore.Components.Endpoints;
1315

@@ -19,7 +21,7 @@ internal class RazorComponentEndpointFactory
1921
internal void AddEndpoints(
2022
#pragma warning restore CA1822 // It's a singleton
2123
List<Endpoint> endpoints,
22-
Type rootComponent,
24+
[DynamicallyAccessedMembers(Component)] Type rootComponent,
2325
PageComponentInfo pageDefinition,
2426
IReadOnlyList<Action<EndpointBuilder>> conventions,
2527
IReadOnlyList<Action<EndpointBuilder>> finallyConventions)

src/Components/Endpoints/src/Builder/RazorComponentsEndpointRouteBuilderExtensions.cs

Lines changed: 6 additions & 4 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.Linq;
56
using Microsoft.AspNetCore.Components.Endpoints;
67
using Microsoft.AspNetCore.Components.Infrastructure;
@@ -9,20 +10,21 @@
910
using Microsoft.AspNetCore.StaticFiles;
1011
using Microsoft.Extensions.DependencyInjection;
1112
using Microsoft.Extensions.FileProviders;
13+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
1214

1315
namespace Microsoft.AspNetCore.Builder;
1416

1517
/// <summary>
16-
///
18+
///
1719
/// </summary>
1820
public static class RazorComponentsEndpointRouteBuilderExtensions
1921
{
2022
/// <summary>
21-
///
23+
///
2224
/// </summary>
2325
/// <param name="endpoints"></param>
2426
/// <returns></returns>
25-
public static RazorComponentEndpointConventionBuilder MapRazorComponents<TRootComponent>(this IEndpointRouteBuilder endpoints)
27+
public static RazorComponentEndpointConventionBuilder MapRazorComponents<[DynamicallyAccessedMembers(Component)] TRootComponent>(this IEndpointRouteBuilder endpoints)
2628
{
2729
ArgumentNullException.ThrowIfNull(endpoints);
2830

@@ -63,7 +65,7 @@ private static void AddBlazorWebJsEndpoint(IEndpointRouteBuilder endpoints)
6365
#endif
6466
}
6567

66-
private static RazorComponentEndpointDataSource<TRootComponent> GetOrCreateDataSource<TRootComponent>(IEndpointRouteBuilder endpoints)
68+
private static RazorComponentEndpointDataSource<TRootComponent> GetOrCreateDataSource<[DynamicallyAccessedMembers(Component)] TRootComponent>(IEndpointRouteBuilder endpoints)
6769
{
6870
var dataSource = endpoints.DataSources.OfType<RazorComponentEndpointDataSource<TRootComponent>>().FirstOrDefault();
6971
if (dataSource == null)

src/Components/Endpoints/src/Builder/RenderModeEndpointProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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.Builder;
56
using Microsoft.AspNetCore.Http;
67
using Microsoft.AspNetCore.Routing;
8+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
79

810
namespace Microsoft.AspNetCore.Components.Endpoints;
911

@@ -31,7 +33,7 @@ public abstract IEnumerable<RouteEndpointBuilder> GetEndpointBuilders(
3133

3234
internal static void AddEndpoints(
3335
List<Endpoint> endpoints,
34-
Type rootComponent,
36+
[DynamicallyAccessedMembers(Component)] Type rootComponent,
3537
IEnumerable<RouteEndpointBuilder> renderModeEndpoints,
3638
IComponentRenderMode renderMode,
3739
List<Action<EndpointBuilder>> conventions,

src/Components/Endpoints/src/Builder/RootComponentMetadata.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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;
5+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
6+
47
namespace Microsoft.AspNetCore.Components.Endpoints;
58

69
/// <summary>
@@ -12,13 +15,14 @@ public class RootComponentMetadata
1215
/// Initializes a new instance of <see cref="RootComponentMetadata"/>.
1316
/// </summary>
1417
/// <param name="rootComponentType">The component type.</param>
15-
public RootComponentMetadata(Type rootComponentType)
18+
public RootComponentMetadata([DynamicallyAccessedMembers(Component)] Type rootComponentType)
1619
{
1720
Type = rootComponentType;
1821
}
1922

2023
/// <summary>
2124
/// Gets the component type.
2225
/// </summary>
26+
[DynamicallyAccessedMembers(Component)]
2327
public Type Type { get; }
2428
}

src/Components/Endpoints/src/DependencyInjection/IComponentPrerenderer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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.Html;
56
using Microsoft.AspNetCore.Http;
7+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
68

79
namespace Microsoft.AspNetCore.Components.Endpoints;
810

@@ -21,7 +23,7 @@ public interface IComponentPrerenderer
2123
/// <returns>A task that completes with the prerendered content.</returns>
2224
ValueTask<IHtmlAsyncContent> PrerenderComponentAsync(
2325
HttpContext httpContext,
24-
Type componentType,
26+
[DynamicallyAccessedMembers(Component)] Type componentType,
2527
IComponentRenderMode renderMode,
2628
ParameterView parameters);
2729

src/Components/Endpoints/src/Discovery/PageComponentBuilder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Linq;
7+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
68

79
namespace Microsoft.AspNetCore.Components.Discovery;
810

@@ -35,6 +37,7 @@ public required IReadOnlyList<string> RouteTemplates
3537
/// <summary>
3638
/// Gets or sets the page type.
3739
/// </summary>
40+
[DynamicallyAccessedMembers(Component)]
3841
public required Type PageType { get; set; }
3942

4043
/// <summary>

src/Components/Endpoints/src/Discovery/PageComponentInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
6+
using static Microsoft.AspNetCore.Internal.LinkerFlags;
57

68
namespace Microsoft.AspNetCore.Components.Discovery;
79

@@ -20,7 +22,7 @@ internal class PageComponentInfo
2022
/// <param name="metadata">The page metadata.</param>
2123
internal PageComponentInfo(
2224
string displayName,
23-
Type type,
25+
[DynamicallyAccessedMembers(Component)] Type type,
2426
string route,
2527
IReadOnlyList<object> metadata)
2628
{
@@ -38,6 +40,7 @@ internal PageComponentInfo(
3840
/// <summary>
3941
/// Gets the page type.
4042
/// </summary>
43+
[DynamicallyAccessedMembers(Component)]
4144
public Type Type { get; }
4245

4346
/// <summary>

0 commit comments

Comments
 (0)