Skip to content

Commit

Permalink
Merge pull request #1741 from danielmarbach/condition
Browse files Browse the repository at this point in the history
Simplify preprocessor directives
  • Loading branch information
lukebakken authored Dec 8, 2024
2 parents e4e05a0 + 8109c96 commit a8dc8ce
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CredentialsRefresherEventSource : EventSource
public void Stopped(string name) => WriteEvent(2, "Stopped", name);

[Event(3)]
#if NET6_0_OR_GREATER
#if NET
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
#endif
public void RefreshedCredentials(string name) => WriteEvent(3, "RefreshedCredentials", name);
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/DefaultEndpointResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace RabbitMQ.Client
{
public class DefaultEndpointResolver : IEndpointResolver
{
#if !NET6_0_OR_GREATER
#if !NET
private readonly Random s_rnd = new Random();
#endif
private readonly List<AmqpTcpEndpoint> _endpoints;
Expand All @@ -49,7 +49,7 @@ public DefaultEndpointResolver(IEnumerable<AmqpTcpEndpoint> tcpEndpoints)

public IEnumerable<AmqpTcpEndpoint> All()
{
#if NET6_0_OR_GREATER
#if NET
return _endpoints.OrderBy(item => Random.Shared.Next());
#else
return _endpoints.OrderBy(item => s_rnd.Next());
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/Impl/AsyncManualResetEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async ValueTask WaitAsync(CancellationToken cancellationToken)
cancellationToken.ThrowIfCancellationRequested();

CancellationTokenRegistration tokenRegistration =
#if NET6_0_OR_GREATER
#if NET
cancellationToken.UnsafeRegister(
static state =>
{
Expand All @@ -87,7 +87,7 @@ public async ValueTask WaitAsync(CancellationToken cancellationToken)
}
finally
{
#if NET6_0_OR_GREATER
#if NET
await tokenRegistration.DisposeAsync()
.ConfigureAwait(false);
#else
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/AsyncRpcContinuations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout, CancellationToken canc
*/
_continuationTimeoutCancellationTokenSource = new CancellationTokenSource(continuationTimeout);

#if NET6_0_OR_GREATER
#if NET
_continuationTimeoutCancellationTokenRegistration = _continuationTimeoutCancellationTokenSource.Token.UnsafeRegister((object? state) =>
{
var tcs = (TaskCompletionSource<T>)state!;
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/Impl/Connection.Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private async ValueTask StartAndTuneAsync(CancellationToken cancellationToken)
{
var connectionStartCell = new TaskCompletionSource<ConnectionStartDetails?>(TaskCreationOptions.RunContinuationsAsynchronously);

#if NET6_0_OR_GREATER
#if NET
using CancellationTokenRegistration ctr = cancellationToken.UnsafeRegister((object? state) =>
{
if (state != null)
Expand Down Expand Up @@ -197,7 +197,7 @@ private IAuthMechanismFactory GetAuthMechanismFactory(string supportedMechanismN
// Our list is in order of preference, the server one is not.
foreach (IAuthMechanismFactory factory in _config.AuthMechanisms)
{
#if NET6_0_OR_GREATER
#if NET
if (supportedMechanismNames.Contains(factory.Name, StringComparison.OrdinalIgnoreCase))
#else
if (supportedMechanismNames.IndexOf(factory.Name, StringComparison.OrdinalIgnoreCase) >= 0)
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/RecordedBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override bool Equals(object? obj)

public override int GetHashCode()
{
#if NET6_0_OR_GREATER
#if NET
return HashCode.Combine(_isQueueBinding, _destination, _source, _routingKey, _arguments);
#else
unchecked
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/SocketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static async Task<ITcpClient> OpenAsync(AmqpTcpEndpoint amqpTcpEndpoint,
{
IPAddress[] ipAddresses = await Dns.GetHostAddressesAsync(
amqpTcpEndpoint.HostName
#if NET6_0_OR_GREATER
#if NET
, cancellationToken
#endif
).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/SslHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static async Task<Stream> TcpUpgradeAsync(Stream tcpStream, SslOption opt

Task TryAuthenticating(SslOption opts)
{
#if NET6_0_OR_GREATER
#if NET
X509RevocationMode certificateRevocationCheckMode = X509RevocationMode.NoCheck;
if (opts.CheckCertificateRevocation)
{
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/WireFormatting.Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static int ReadShortstr(ReadOnlySpan<byte> span, out string value)
// equals span.Length >= byteCount + 1
if (span.Length > byteCount)
{
#if NETCOREAPP
#if NET
value = UTF8.GetString(span.Slice(1, byteCount));
#else
unsafe
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/WireFormatting.Write.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static int GetArrayByteCount(IList? val)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NETCOREAPP
#if NET
public static int GetByteCount(ReadOnlySpan<char> val) => val.IsEmpty ? 0 : UTF8.GetByteCount(val);
#else
public static int GetByteCount(string val) => string.IsNullOrEmpty(val) ? 0 : UTF8.GetByteCount(val);
Expand Down
6 changes: 3 additions & 3 deletions projects/RabbitMQ.Client/Logging/RabbitMqClientEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal sealed partial class RabbitMqClientEventSource : EventSource
{
public static readonly RabbitMqClientEventSource Log = new RabbitMqClientEventSource();

#if NET6_0_OR_GREATER
#if NET
private readonly PollingCounter _connectionOpenedCounter;
private readonly PollingCounter _openConnectionCounter;
private readonly PollingCounter _channelOpenedCounter;
Expand All @@ -54,7 +54,7 @@ internal sealed partial class RabbitMqClientEventSource : EventSource
public RabbitMqClientEventSource()
: base("rabbitmq-client")
{
#if NET6_0_OR_GREATER
#if NET
_connectionOpenedCounter = new PollingCounter("total-connections-opened", this, () => s_connectionsOpened)
{
DisplayName = "Total connections opened"
Expand Down Expand Up @@ -128,7 +128,7 @@ public void Warn(string message)
}
}

#if NET6_0_OR_GREATER
#if NET
[Event(3, Keywords = Keywords.Log, Level = EventLevel.Error)]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
public void Error(string message, RabbitMqExceptionDetail ex)
Expand Down
8 changes: 4 additions & 4 deletions projects/RabbitMQ.Client/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace RabbitMQ.Client
{
internal static class TaskExtensions
{
#if NET6_0_OR_GREATER
#if NET
public static bool IsCompletedSuccessfully(this Task task)
{
return task.IsCompletedSuccessfully;
Expand All @@ -49,7 +49,7 @@ public static bool IsCompletedSuccessfully(this Task task)
}
#endif

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

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

public static Task WaitAsync(this Task task, TimeSpan timeout)
{
#if NET6_0_OR_GREATER
#if NET
if (task.IsCompletedSuccessfully)
{
return task;
Expand Down Expand Up @@ -171,7 +171,7 @@ public static async ValueTask TimeoutAfter(this ValueTask valueTask, TimeSpan ti
return;
}

#if NET6_0_OR_GREATER
#if NET
Task task = valueTask.AsTask();
await task.WaitAsync(timeout)
.ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/TcpClientAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public TcpClientAdapter(Socket socket)
_sock = socket ?? throw new InvalidOperationException("socket must not be null");
}

#if NET6_0_OR_GREATER
#if NET
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken = default)
{
return _sock.ConnectAsync(ep, port, cancellationToken).AsTask();
Expand Down
2 changes: 1 addition & 1 deletion projects/Test/Common/IntegrationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public abstract class IntegrationFixture : IAsyncLifetime
static IntegrationFixture()
{

#if NET6_0_OR_GREATER
#if NET
S_Random = Random.Shared;
#else
S_Random = new Random();
Expand Down
2 changes: 1 addition & 1 deletion projects/Test/Common/TestOutputWriterEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
try
{
#if NET6_0_OR_GREATER
#if NET
if (eventData.Payload.Count > 0)
{
string payloadName = eventData.PayloadNames[0];
Expand Down

0 comments on commit a8dc8ce

Please sign in to comment.