Skip to content

Commit 5322d6b

Browse files
authored
precompile condition clean (#2528)
1 parent 439a3b8 commit 5322d6b

File tree

56 files changed

+62
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+62
-413
lines changed

perf/benchmarkapps/GrpcAspNetCoreServer/Program.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,8 @@ public static IHostBuilder CreateHostBuilder(string[] args)
120120
{
121121
Console.WriteLine($"Console Logging enabled with level '{logLevel}'");
122122

123-
loggerFactory
124-
#if NET5_0_OR_GREATER
125-
.AddSimpleConsole(o => o.TimestampFormat = "ss.ffff ")
126-
#else
127-
.AddConsole(o => o.TimestampFormat = "ss.ffff ")
128-
#endif
129-
.SetMinimumLevel(logLevel);
123+
loggerFactory.AddSimpleConsole(o => o.TimestampFormat = "ss.ffff ")
124+
.SetMinimumLevel(logLevel);
130125
}
131126
})
132127
.UseDefaultServiceProvider((context, options) =>
@@ -163,7 +158,6 @@ private static void ConfigureListenOptions(ListenOptions listenOptions, IConfigu
163158
}
164159
});
165160
}
166-
#if NET6_0_OR_GREATER
167161
else if (protocol.Equals("h3", StringComparison.OrdinalIgnoreCase))
168162
{
169163
listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
@@ -177,7 +171,6 @@ private static void ConfigureListenOptions(ListenOptions listenOptions, IConfigu
177171
}
178172
});
179173
}
180-
#endif
181174
else if (protocol.Equals("h2c", StringComparison.OrdinalIgnoreCase))
182175
{
183176
listenOptions.Protocols = HttpProtocols.Http2;

perf/benchmarkapps/GrpcAspNetCoreServer/Startup.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -21,9 +21,7 @@
2121
using Grpc.Shared;
2222
using Grpc.Testing;
2323
using Grpc.Tests.Shared;
24-
#if NET5_0_OR_GREATER
2524
using Microsoft.AspNetCore.Authentication.Certificate;
26-
#endif
2725
using Newtonsoft.Json;
2826

2927
namespace GrpcAspNetCoreServer;
@@ -41,10 +39,8 @@ public void ConfigureServices(IServiceCollection services)
4139
{
4240
services.AddGrpc(o =>
4341
{
44-
#if NET5_0_OR_GREATER
4542
// Small performance benefit to not add catch-all routes to handle UNIMPLEMENTED for unknown services
4643
o.IgnoreUnknownServices = true;
47-
#endif
4844
});
4945
services.Configure<RouteOptions>(c =>
5046
{
@@ -54,7 +50,6 @@ public void ConfigureServices(IServiceCollection services)
5450
services.AddSingleton<BenchmarkServiceImpl>();
5551
services.AddControllers();
5652

57-
#if NET5_0_OR_GREATER
5853
bool.TryParse(_config["enableCertAuth"], out var enableCertAuth);
5954
if (enableCertAuth)
6055
{
@@ -67,7 +62,6 @@ public void ConfigureServices(IServiceCollection services)
6762
options.AllowedCertificateTypes = CertificateTypes.All;
6863
});
6964
}
70-
#endif
7165
}
7266

7367
public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicationLifetime)
@@ -83,14 +77,12 @@ public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicat
8377

8478
app.UseRouting();
8579

86-
#if NET5_0_OR_GREATER
8780
bool.TryParse(_config["enableCertAuth"], out var enableCertAuth);
8881
if (enableCertAuth)
8982
{
9083
app.UseAuthentication();
9184
app.UseAuthorization();
9285
}
93-
#endif
9486

9587
#if GRPC_WEB
9688
bool.TryParse(_config["enableGrpcWeb"], out var enableGrpcWeb);
@@ -139,12 +131,10 @@ public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicat
139131

140132
private void ConfigureAuthorization(IEndpointConventionBuilder builder)
141133
{
142-
#if NET5_0_OR_GREATER
143134
bool.TryParse(_config["enableCertAuth"], out var enableCertAuth);
144135
if (enableCertAuth)
145136
{
146137
builder.RequireAuthorization();
147138
}
148-
#endif
149139
}
150140
}

perf/benchmarkapps/GrpcClient/ClientOptions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -23,10 +23,8 @@ namespace GrpcClient;
2323
public class ClientOptions
2424
{
2525
public Uri? Url { get; set; }
26-
#if NET5_0_OR_GREATER
2726
public string? UdsFileName { get; set; }
2827
public string? NamedPipeName { get; set; }
29-
#endif
3028
public int Connections { get; set; }
3129
public int Warmup { get; set; }
3230
public int Duration { get; set; }
@@ -41,4 +39,4 @@ public class ClientOptions
4139
public GrpcClientType GrpcClientType { get; set; }
4240
public int Streams { get; set; }
4341
public int Deadline { get; set; }
44-
}
42+
}

perf/benchmarkapps/GrpcClient/NamedPipeConnectionFactory.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -19,8 +19,6 @@
1919
using System.IO.Pipes;
2020
using System.Security.Principal;
2121

22-
#if NET5_0_OR_GREATER
23-
2422
namespace GrpcClient;
2523

2624
public class NamedPipeConnectionFactory
@@ -56,5 +54,3 @@ public async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _,
5654
}
5755
}
5856
}
59-
60-
#endif

perf/benchmarkapps/GrpcClient/Program.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,6 @@ private static ChannelBase CreateChannel(string target)
465465
var address = useTls ? "https://" : "http://";
466466
address += target;
467467

468-
#if NETCOREAPP3_1
469-
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
470-
#endif
471-
472468
var httpClientHandler = new SocketsHttpHandler();
473469
httpClientHandler.UseProxy = false;
474470
httpClientHandler.AllowAutoRedirect = false;
@@ -479,7 +475,7 @@ private static ChannelBase CreateChannel(string target)
479475
var clientCertificates = X509CertificateLoader.LoadPkcs12CollectionFromFile(certPath, "1111");
480476
httpClientHandler.SslOptions.ClientCertificates = clientCertificates;
481477
}
482-
#if NET5_0_OR_GREATER
478+
483479
if (!string.IsNullOrEmpty(_options.UdsFileName))
484480
{
485481
var connectionFactory = new UnixDomainSocketConnectionFactory(new UnixDomainSocketEndPoint(ResolveUdsPath(_options.UdsFileName)));
@@ -490,7 +486,6 @@ private static ChannelBase CreateChannel(string target)
490486
var connectionFactory = new NamedPipeConnectionFactory(_options.NamedPipeName);
491487
httpClientHandler.ConnectCallback = connectionFactory.ConnectAsync;
492488
}
493-
#endif
494489

495490
httpClientHandler.SslOptions.RemoteCertificateValidationCallback =
496491
(object sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslPolicyErrors) => true;
@@ -509,11 +504,7 @@ private static ChannelBase CreateChannel(string target)
509504

510505
return GrpcChannel.ForAddress(address, new GrpcChannelOptions
511506
{
512-
#if NET5_0_OR_GREATER
513507
HttpHandler = httpMessageHandler,
514-
#else
515-
HttpClient = new HttpClient(httpMessageHandler),
516-
#endif
517508
LoggerFactory = _loggerFactory,
518509
HttpVersion = versionOverride
519510
});

perf/benchmarkapps/GrpcClient/UnixDomainSocketConnectionFactory.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -19,8 +19,6 @@
1919
using System.Net;
2020
using System.Net.Sockets;
2121

22-
#if NET5_0_OR_GREATER
23-
2422
namespace GrpcClient;
2523

2624
public class UnixDomainSocketConnectionFactory
@@ -48,5 +46,3 @@ public async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _, Canc
4846
}
4947
}
5048
}
51-
52-
#endif

src/Grpc.AspNetCore.Server/GrpcEndpointRouteBuilderExtensions.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ public static class GrpcEndpointRouteBuilderExtensions
3636
/// <typeparam name="TService">The service type to map requests to.</typeparam>
3737
/// <param name="builder">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
3838
/// <returns>A <see cref="GrpcServiceEndpointConventionBuilder"/> for endpoints associated with the service.</returns>
39-
public static GrpcServiceEndpointConventionBuilder MapGrpcService<
40-
#if NET5_0_OR_GREATER
41-
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
42-
#endif
43-
TService>(this IEndpointRouteBuilder builder) where TService : class
39+
public static GrpcServiceEndpointConventionBuilder MapGrpcService<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService>(this IEndpointRouteBuilder builder) where TService : class
4440
{
4541
ArgumentNullThrowHelper.ThrowIfNull(builder);
4642

src/Grpc.AspNetCore.Server/GrpcMethodMetadata.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ public sealed class GrpcMethodMetadata
3333
/// </summary>
3434
/// <param name="serviceType">The implementing service type.</param>
3535
/// <param name="method">The method representation.</param>
36-
public GrpcMethodMetadata(
37-
#if NET5_0_OR_GREATER
38-
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
39-
#endif
40-
Type serviceType,
41-
IMethod method)
36+
public GrpcMethodMetadata([DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] Type serviceType, IMethod method)
4237
{
4338
ArgumentNullThrowHelper.ThrowIfNull(serviceType);
4439
ArgumentNullThrowHelper.ThrowIfNull(method);
@@ -50,9 +45,7 @@ public GrpcMethodMetadata(
5045
/// <summary>
5146
/// Gets the implementing service type.
5247
/// </summary>
53-
#if NET5_0_OR_GREATER
5448
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
55-
#endif
5649
public Type ServiceType { get; }
5750

5851
/// <summary>

src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -25,11 +25,7 @@ namespace Grpc.AspNetCore.Server;
2525
/// A <typeparamref name="TGrpcService"/> activator abstraction.
2626
/// </summary>
2727
/// <typeparam name="TGrpcService">The service type.</typeparam>
28-
public interface IGrpcServiceActivator<
29-
#if NET5_0_OR_GREATER
30-
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
31-
#endif
32-
TGrpcService> where TGrpcService : class
28+
public interface IGrpcServiceActivator<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TGrpcService> where TGrpcService : class
3329
{
3430
/// <summary>
3531
/// Creates a service.

src/Grpc.AspNetCore.Server/InterceptorCollection.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ public class InterceptorCollection : Collection<InterceptorRegistration>
3333
/// </summary>
3434
/// <typeparam name="TInterceptor">The interceptor type.</typeparam>
3535
/// <param name="args">The list of arguments to pass to the interceptor constructor when creating an instance.</param>
36-
public void Add<
37-
#if NET5_0_OR_GREATER
38-
[DynamicallyAccessedMembers(InterceptorRegistration.InterceptorAccessibility)]
39-
#endif
40-
TInterceptor>(params object[] args) where TInterceptor : Interceptor
36+
public void Add<[DynamicallyAccessedMembers(InterceptorRegistration.InterceptorAccessibility)] TInterceptor>(params object[] args) where TInterceptor : Interceptor
4137
{
4238
Add(typeof(TInterceptor), args);
4339
}
@@ -47,11 +43,7 @@ public void Add<
4743
/// </summary>
4844
/// <param name="interceptorType">The interceptor type.</param>
4945
/// <param name="args">The list of arguments to pass to the interceptor constructor when creating an instance.</param>
50-
public void Add(
51-
#if NET5_0_OR_GREATER
52-
[DynamicallyAccessedMembers(InterceptorRegistration.InterceptorAccessibility)]
53-
#endif
54-
Type interceptorType, params object[] args)
46+
public void Add([DynamicallyAccessedMembers(InterceptorRegistration.InterceptorAccessibility)] Type interceptorType, params object[] args)
5547
{
5648
ArgumentNullThrowHelper.ThrowIfNull(interceptorType);
5749

0 commit comments

Comments
 (0)