Skip to content

Commit a8dc8ce

Browse files
authored
Merge pull request #1741 from danielmarbach/condition
Simplify preprocessor directives
2 parents e4e05a0 + 8109c96 commit a8dc8ce

15 files changed

+23
-23
lines changed

projects/RabbitMQ.Client.OAuth2/CredentialsRefresherEventSource.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class CredentialsRefresherEventSource : EventSource
4646
public void Stopped(string name) => WriteEvent(2, "Stopped", name);
4747

4848
[Event(3)]
49-
#if NET6_0_OR_GREATER
49+
#if NET
5050
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
5151
#endif
5252
public void RefreshedCredentials(string name) => WriteEvent(3, "RefreshedCredentials", name);

projects/RabbitMQ.Client/DefaultEndpointResolver.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace RabbitMQ.Client
3737
{
3838
public class DefaultEndpointResolver : IEndpointResolver
3939
{
40-
#if !NET6_0_OR_GREATER
40+
#if !NET
4141
private readonly Random s_rnd = new Random();
4242
#endif
4343
private readonly List<AmqpTcpEndpoint> _endpoints;
@@ -49,7 +49,7 @@ public DefaultEndpointResolver(IEnumerable<AmqpTcpEndpoint> tcpEndpoints)
4949

5050
public IEnumerable<AmqpTcpEndpoint> All()
5151
{
52-
#if NET6_0_OR_GREATER
52+
#if NET
5353
return _endpoints.OrderBy(item => Random.Shared.Next());
5454
#else
5555
return _endpoints.OrderBy(item => s_rnd.Next());

projects/RabbitMQ.Client/Impl/AsyncManualResetEvent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public async ValueTask WaitAsync(CancellationToken cancellationToken)
6464
cancellationToken.ThrowIfCancellationRequested();
6565

6666
CancellationTokenRegistration tokenRegistration =
67-
#if NET6_0_OR_GREATER
67+
#if NET
6868
cancellationToken.UnsafeRegister(
6969
static state =>
7070
{
@@ -87,7 +87,7 @@ public async ValueTask WaitAsync(CancellationToken cancellationToken)
8787
}
8888
finally
8989
{
90-
#if NET6_0_OR_GREATER
90+
#if NET
9191
await tokenRegistration.DisposeAsync()
9292
.ConfigureAwait(false);
9393
#else

projects/RabbitMQ.Client/Impl/AsyncRpcContinuations.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout, CancellationToken canc
6060
*/
6161
_continuationTimeoutCancellationTokenSource = new CancellationTokenSource(continuationTimeout);
6262

63-
#if NET6_0_OR_GREATER
63+
#if NET
6464
_continuationTimeoutCancellationTokenRegistration = _continuationTimeoutCancellationTokenSource.Token.UnsafeRegister((object? state) =>
6565
{
6666
var tcs = (TaskCompletionSource<T>)state!;

projects/RabbitMQ.Client/Impl/Connection.Commands.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private async ValueTask StartAndTuneAsync(CancellationToken cancellationToken)
7676
{
7777
var connectionStartCell = new TaskCompletionSource<ConnectionStartDetails?>(TaskCreationOptions.RunContinuationsAsynchronously);
7878

79-
#if NET6_0_OR_GREATER
79+
#if NET
8080
using CancellationTokenRegistration ctr = cancellationToken.UnsafeRegister((object? state) =>
8181
{
8282
if (state != null)
@@ -197,7 +197,7 @@ private IAuthMechanismFactory GetAuthMechanismFactory(string supportedMechanismN
197197
// Our list is in order of preference, the server one is not.
198198
foreach (IAuthMechanismFactory factory in _config.AuthMechanisms)
199199
{
200-
#if NET6_0_OR_GREATER
200+
#if NET
201201
if (supportedMechanismNames.Contains(factory.Name, StringComparison.OrdinalIgnoreCase))
202202
#else
203203
if (supportedMechanismNames.IndexOf(factory.Name, StringComparison.OrdinalIgnoreCase) >= 0)

projects/RabbitMQ.Client/Impl/RecordedBinding.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public override bool Equals(object? obj)
106106

107107
public override int GetHashCode()
108108
{
109-
#if NET6_0_OR_GREATER
109+
#if NET
110110
return HashCode.Combine(_isQueueBinding, _destination, _source, _routingKey, _arguments);
111111
#else
112112
unchecked

projects/RabbitMQ.Client/Impl/SocketFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static async Task<ITcpClient> OpenAsync(AmqpTcpEndpoint amqpTcpEndpoint,
4545
{
4646
IPAddress[] ipAddresses = await Dns.GetHostAddressesAsync(
4747
amqpTcpEndpoint.HostName
48-
#if NET6_0_OR_GREATER
48+
#if NET
4949
, cancellationToken
5050
#endif
5151
).ConfigureAwait(false);

projects/RabbitMQ.Client/Impl/SslHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static async Task<Stream> TcpUpgradeAsync(Stream tcpStream, SslOption opt
6868

6969
Task TryAuthenticating(SslOption opts)
7070
{
71-
#if NET6_0_OR_GREATER
71+
#if NET
7272
X509RevocationMode certificateRevocationCheckMode = X509RevocationMode.NoCheck;
7373
if (opts.CheckCertificateRevocation)
7474
{

projects/RabbitMQ.Client/Impl/WireFormatting.Read.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static int ReadShortstr(ReadOnlySpan<byte> span, out string value)
172172
// equals span.Length >= byteCount + 1
173173
if (span.Length > byteCount)
174174
{
175-
#if NETCOREAPP
175+
#if NET
176176
value = UTF8.GetString(span.Slice(1, byteCount));
177177
#else
178178
unsafe

projects/RabbitMQ.Client/Impl/WireFormatting.Write.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static int GetArrayByteCount(IList? val)
8686
}
8787

8888
[MethodImpl(MethodImplOptions.AggressiveInlining)]
89-
#if NETCOREAPP
89+
#if NET
9090
public static int GetByteCount(ReadOnlySpan<char> val) => val.IsEmpty ? 0 : UTF8.GetByteCount(val);
9191
#else
9292
public static int GetByteCount(string val) => string.IsNullOrEmpty(val) ? 0 : UTF8.GetByteCount(val);

projects/RabbitMQ.Client/Logging/RabbitMqClientEventSource.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal sealed partial class RabbitMqClientEventSource : EventSource
4040
{
4141
public static readonly RabbitMqClientEventSource Log = new RabbitMqClientEventSource();
4242

43-
#if NET6_0_OR_GREATER
43+
#if NET
4444
private readonly PollingCounter _connectionOpenedCounter;
4545
private readonly PollingCounter _openConnectionCounter;
4646
private readonly PollingCounter _channelOpenedCounter;
@@ -54,7 +54,7 @@ internal sealed partial class RabbitMqClientEventSource : EventSource
5454
public RabbitMqClientEventSource()
5555
: base("rabbitmq-client")
5656
{
57-
#if NET6_0_OR_GREATER
57+
#if NET
5858
_connectionOpenedCounter = new PollingCounter("total-connections-opened", this, () => s_connectionsOpened)
5959
{
6060
DisplayName = "Total connections opened"
@@ -128,7 +128,7 @@ public void Warn(string message)
128128
}
129129
}
130130

131-
#if NET6_0_OR_GREATER
131+
#if NET
132132
[Event(3, Keywords = Keywords.Log, Level = EventLevel.Error)]
133133
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
134134
public void Error(string message, RabbitMqExceptionDetail ex)

projects/RabbitMQ.Client/TaskExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace RabbitMQ.Client
3737
{
3838
internal static class TaskExtensions
3939
{
40-
#if NET6_0_OR_GREATER
40+
#if NET
4141
public static bool IsCompletedSuccessfully(this Task task)
4242
{
4343
return task.IsCompletedSuccessfully;
@@ -49,7 +49,7 @@ public static bool IsCompletedSuccessfully(this Task task)
4949
}
5050
#endif
5151

52-
#if !NET6_0_OR_GREATER
52+
#if !NET
5353
private static readonly TaskContinuationOptions s_tco = TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously;
5454
private static void IgnoreTaskContinuation(Task t, object s) => t.Exception.Handle(e => true);
5555

@@ -126,7 +126,7 @@ private static async Task DoWaitAsync(this Task task, CancellationToken cancella
126126

127127
public static Task WaitAsync(this Task task, TimeSpan timeout)
128128
{
129-
#if NET6_0_OR_GREATER
129+
#if NET
130130
if (task.IsCompletedSuccessfully)
131131
{
132132
return task;
@@ -171,7 +171,7 @@ public static async ValueTask TimeoutAfter(this ValueTask valueTask, TimeSpan ti
171171
return;
172172
}
173173

174-
#if NET6_0_OR_GREATER
174+
#if NET
175175
Task task = valueTask.AsTask();
176176
await task.WaitAsync(timeout)
177177
.ConfigureAwait(false);

projects/RabbitMQ.Client/TcpClientAdapter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public TcpClientAdapter(Socket socket)
2020
_sock = socket ?? throw new InvalidOperationException("socket must not be null");
2121
}
2222

23-
#if NET6_0_OR_GREATER
23+
#if NET
2424
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken = default)
2525
{
2626
return _sock.ConnectAsync(ep, port, cancellationToken).AsTask();

projects/Test/Common/IntegrationFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public abstract class IntegrationFixture : IAsyncLifetime
8989
static IntegrationFixture()
9090
{
9191

92-
#if NET6_0_OR_GREATER
92+
#if NET
9393
S_Random = Random.Shared;
9494
#else
9595
S_Random = new Random();

projects/Test/Common/TestOutputWriterEventListener.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
7676
{
7777
try
7878
{
79-
#if NET6_0_OR_GREATER
79+
#if NET
8080
if (eventData.Payload.Count > 0)
8181
{
8282
string payloadName = eventData.PayloadNames[0];

0 commit comments

Comments
 (0)