Skip to content

Commit cba3002

Browse files
Annotate Http.Connections for trimming (#52918)
1 parent bff3333 commit cba3002

File tree

9 files changed

+22
-5
lines changed

9 files changed

+22
-5
lines changed

eng/TrimmableProjects.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
<TrimmableProject Include="Microsoft.AspNetCore.SpaServices.Extensions" />
8686
<TrimmableProject Include="Microsoft.AspNetCore.StaticFiles" />
8787
<TrimmableProject Include="Microsoft.AspNetCore.WebSockets" />
88+
<TrimmableProject Include="Microsoft.AspNetCore.Http.Connections.Common" />
89+
<TrimmableProject Include="Microsoft.AspNetCore.Http.Connections" />
90+
<TrimmableProject Include="Microsoft.AspNetCore.SignalR.Common" />
8891
<TrimmableProject Include="Microsoft.AspNetCore.Components.Authorization" />
8992
<TrimmableProject Include="Microsoft.AspNetCore.Components" />
9093
<TrimmableProject Include="Microsoft.AspNetCore.Components.CustomElements" />

src/Shared/CodeAnalysis/DynamicallyAccessedMemberTypes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ internal enum DynamicallyAccessedMemberTypes
8686
/// </summary>
8787
NonPublicEvents = 0x1000,
8888

89+
/// <summary>
90+
/// Specifies all interfaces implemented by the type.
91+
/// </summary>
92+
Interfaces = 0x2000,
93+
8994
/// <summary>
9095
/// Specifies all members.
9196
/// </summary>

src/SignalR/clients/csharp/Client.Core/src/Microsoft.AspNetCore.SignalR.Client.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<Compile Include="$(SharedSourceRoot)ThrowHelpers\ArgumentNullThrowHelper.cs" LinkBase="Shared" />
2020
<Compile Include="$(SharedSourceRoot)ThrowHelpers\ObjectDisposedThrowHelper.cs" LinkBase="Shared" />
2121
<Compile Include="$(SharedSourceRoot)CallerArgument\CallerArgumentExpressionAttribute.cs" LinkBase="Shared" />
22+
<Compile Include="$(SharedSourceRoot)CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" LinkBase="Shared" />
23+
<Compile Include="$(SharedSourceRoot)CodeAnalysis\DynamicallyAccessedMemberTypes.cs" LinkBase="Shared" />
2224
</ItemGroup>
2325

2426
<ItemGroup>

src/SignalR/common/Http.Connections.Common/src/Microsoft.AspNetCore.Http.Connections.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<RootNamespace>Microsoft.AspNetCore.Http.Connections</RootNamespace>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1010
<Nullable>enable</Nullable>
11+
<IsTrimmable>true</IsTrimmable>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static ConnectionEndpointRouteBuilder MapConnections(this IEndpointRouteB
3535
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
3636
/// <param name="pattern">The route pattern.</param>
3737
/// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns>
38-
public static ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHandler>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern) where TConnectionHandler : ConnectionHandler
38+
public static ConnectionEndpointRouteBuilder MapConnectionHandler<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConnectionHandler>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern) where TConnectionHandler : ConnectionHandler
3939
{
4040
return endpoints.MapConnectionHandler<TConnectionHandler>(pattern, configureOptions: null);
4141
}
@@ -48,7 +48,7 @@ public static ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHan
4848
/// <param name="pattern">The route pattern.</param>
4949
/// <param name="configureOptions">A callback to configure dispatcher options.</param>
5050
/// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns>
51-
public static ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHandler>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Action<HttpConnectionDispatcherOptions>? configureOptions) where TConnectionHandler : ConnectionHandler
51+
public static ConnectionEndpointRouteBuilder MapConnectionHandler<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConnectionHandler>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Action<HttpConnectionDispatcherOptions>? configureOptions) where TConnectionHandler : ConnectionHandler
5252
{
5353
var options = new HttpConnectionDispatcherOptions();
5454
configureOptions?.Invoke(options);

src/SignalR/common/Http.Connections/src/Microsoft.AspNetCore.Http.Connections.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<IsPackable>false</IsPackable>
99
<Nullable>enable</Nullable>
10+
<IsTrimmable>true</IsTrimmable>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

src/SignalR/common/Shared/ReflectionHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Linq;
78
using System.Threading.Channels;
89

@@ -12,7 +13,7 @@ internal static class ReflectionHelper
1213
{
1314
// mustBeDirectType - Hub methods must use the base 'stream' type and not be a derived class that just implements the 'stream' type
1415
// and 'stream' types from the client are allowed to inherit from accepted 'stream' types
15-
public static bool IsStreamingType(Type type, bool mustBeDirectType = false)
16+
public static bool IsStreamingType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type, bool mustBeDirectType = false)
1617
{
1718
// TODO #2594 - add Streams here, to make sending files easy
1819

@@ -36,7 +37,7 @@ public static bool IsStreamingType(Type type, bool mustBeDirectType = false)
3637
return false;
3738
}
3839

39-
public static bool IsIAsyncEnumerable(Type type)
40+
public static bool IsIAsyncEnumerable([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type)
4041
{
4142
if (type.IsGenericType)
4243
{

src/SignalR/common/SignalR.Common/src/Microsoft.AspNetCore.SignalR.Common.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>Common serialization primitives for SignalR Clients Servers</Description>
@@ -8,6 +8,7 @@
88
<RootNamespace>Microsoft.AspNetCore.SignalR</RootNamespace>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1010
<Nullable>enable</Nullable>
11+
<IsTrimmable>true</IsTrimmable>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

src/Tools/Tools.slnf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
"src\\Servers\\Kestrel\\Transport.NamedPipes\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.csproj",
101101
"src\\Servers\\Kestrel\\Transport.Quic\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj",
102102
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj",
103+
"src\\SignalR\\common\\Http.Connections.Common\\src\\Microsoft.AspNetCore.Http.Connections.Common.csproj",
104+
"src\\SignalR\\common\\Http.Connections\\src\\Microsoft.AspNetCore.Http.Connections.csproj",
105+
"src\\SignalR\\common\\SignalR.Common\\src\\Microsoft.AspNetCore.SignalR.Common.csproj",
103106
"src\\Testing\\src\\Microsoft.AspNetCore.InternalTesting.csproj",
104107
"src\\Tools\\Extensions.ApiDescription.Client\\src\\Microsoft.Extensions.ApiDescription.Client.csproj",
105108
"src\\Tools\\Extensions.ApiDescription.Client\\test\\Microsoft.Extensions.ApiDescription.Client.Tests.csproj",

0 commit comments

Comments
 (0)