Skip to content

Commit 9bea515

Browse files
committed
Use pattern matching for nullable Boolean tests.
1 parent 314bead commit 9bea515

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
486486
else
487487
{
488488
// pipelining is not currently compatible with compression
489-
m_supportsPipelining = !cs.UseCompression && (cs.Pipelining ?? true);
489+
m_supportsPipelining = !cs.UseCompression && cs.Pipelining is not false;
490490

491491
// for pipelining, concatenate reset connection and SET NAMES query into one buffer
492492
if (m_supportsPipelining)
@@ -1764,13 +1764,13 @@ private void VerifyState(State state1, State state2, State state3, State state4,
17641764
}
17651765
}
17661766

1767-
internal bool SslIsEncrypted => m_sslStream?.IsEncrypted ?? false;
1767+
internal bool SslIsEncrypted => m_sslStream?.IsEncrypted is true;
17681768

1769-
internal bool SslIsSigned => m_sslStream?.IsSigned ?? false;
1769+
internal bool SslIsSigned => m_sslStream?.IsSigned is true;
17701770

1771-
internal bool SslIsAuthenticated => m_sslStream?.IsAuthenticated ?? false;
1771+
internal bool SslIsAuthenticated => m_sslStream?.IsAuthenticated is true;
17721772

1773-
internal bool SslIsMutuallyAuthenticated => m_sslStream?.IsMutuallyAuthenticated ?? false;
1773+
internal bool SslIsMutuallyAuthenticated => m_sslStream?.IsMutuallyAuthenticated is true;
17741774

17751775
internal SslProtocols SslProtocol => m_sslStream?.SslProtocol ?? SslProtocols.None;
17761776

src/MySqlConnector/MySqlBulkCopy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ await m_valuesEnumerator.MoveNextAsync().ConfigureAwait(false) :
426426
}
427427
}
428428

429-
if (outputIndex != 0 && !(eventArgs?.Abort ?? false))
429+
if (outputIndex != 0 && eventArgs?.Abort is not true)
430430
{
431431
var payload2 = new PayloadData(new ArraySegment<byte>(buffer, 0, outputIndex));
432432
await m_connection.Session.SendReplyAsync(payload2, ioBehavior, cancellationToken).ConfigureAwait(false);
@@ -435,7 +435,7 @@ await m_valuesEnumerator.MoveNextAsync().ConfigureAwait(false) :
435435
finally
436436
{
437437
ArrayPool<byte>.Shared.Return(buffer);
438-
m_wasAborted = eventArgs?.Abort ?? false;
438+
m_wasAborted = eventArgs?.Abort is true;
439439
}
440440

441441
static bool WriteValue(MySqlConnection connection, object value, ref int inputIndex, ref Encoder? utf8Encoder, Span<byte> output, out int bytesWritten)

src/MySqlConnector/MySqlCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private bool NeedsPrepare(out Exception? exception)
174174
exception = new InvalidOperationException("Connection must be Open; current state is {0}".FormatInvariant(Connection.State));
175175
else if (string.IsNullOrWhiteSpace(CommandText))
176176
exception = new InvalidOperationException("CommandText must be specified");
177-
else if (Connection?.HasActiveReader ?? false)
177+
else if (Connection?.HasActiveReader is true)
178178
exception = new InvalidOperationException("Cannot call Prepare when there is an open DataReader for this command's connection; it must be closed first.");
179179

180180
if (exception is not null || Connection!.IgnorePrepare)

src/MySqlConnector/MySqlConnection.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public override void EnlistTransaction(System.Transactions.Transaction? transact
181181
throw new InvalidOperationException("Connection is not open.");
182182

183183
// ignore reenlistment of same connection in same transaction
184-
if (m_enlistedTransaction?.Transaction.Equals(transaction) ?? false)
184+
if (m_enlistedTransaction?.Transaction.Equals(transaction) is true)
185185
return;
186186

187187
if (m_enlistedTransaction is not null)
@@ -858,7 +858,7 @@ internal void Cancel(ICancellableCommand command, int commandId, bool isCancel)
858858
internal IOBehavior AsyncIOBehavior => GetConnectionSettings().ForceSynchronous ? IOBehavior.Synchronous : IOBehavior.Asynchronous;
859859

860860
// Defaults to IOBehavior.Synchronous if the connection hasn't been opened yet; only use if it's a no-op for a closed connection.
861-
internal IOBehavior SimpleAsyncIOBehavior => (m_connectionSettings?.ForceSynchronous ?? false) ? IOBehavior.Synchronous : IOBehavior.Asynchronous;
861+
internal IOBehavior SimpleAsyncIOBehavior => (m_connectionSettings?.ForceSynchronous is true) ? IOBehavior.Synchronous : IOBehavior.Asynchronous;
862862

863863
internal MySqlSslMode SslMode => GetInitializedConnectionSettings().SslMode;
864864

@@ -931,12 +931,12 @@ private async ValueTask<ServerSession> CreateSessionAsync(ConnectionPool? pool,
931931
return session;
932932
}
933933
}
934-
catch (OperationCanceledException) when (timeoutSource?.IsCancellationRequested ?? false)
934+
catch (OperationCanceledException) when (timeoutSource?.IsCancellationRequested is true)
935935
{
936-
var messageSuffix = (pool?.IsEmpty ?? false) ? " All pooled connections are in use." : "";
936+
var messageSuffix = (pool?.IsEmpty is true) ? " All pooled connections are in use." : "";
937937
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired." + messageSuffix);
938938
}
939-
catch (MySqlException ex) when ((timeoutSource?.IsCancellationRequested ?? false) || (ex.ErrorCode == MySqlErrorCode.CommandTimeoutExpired))
939+
catch (MySqlException ex) when ((timeoutSource?.IsCancellationRequested is true) || (ex.ErrorCode == MySqlErrorCode.CommandTimeoutExpired))
940940
{
941941
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.", ex);
942942
}
@@ -990,7 +990,7 @@ private async Task CloseAsync(bool changeState, IOBehavior ioBehavior)
990990
if (m_activeReader is null &&
991991
CurrentTransaction is null &&
992992
m_enlistedTransaction is null &&
993-
(m_connectionSettings?.Pooling ?? false))
993+
(m_connectionSettings?.Pooling is true))
994994
{
995995
m_cachedProcedures = null;
996996
if (m_session is not null)

tests/SideBySide/TestUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static string GetSkipReason(ServerFeatures serverFeatures, ConfigSettings
8282

8383
if (configSettings.HasFlag(ConfigSettings.KnownClientCertificate))
8484
{
85-
if (!((csb.CertificateFile?.EndsWith("ssl-client.pfx", StringComparison.OrdinalIgnoreCase) ?? false) || (csb.SslKey?.EndsWith("ssl-client-key.pem", StringComparison.OrdinalIgnoreCase) ?? false)))
85+
if (!((csb.CertificateFile?.EndsWith("ssl-client.pfx", StringComparison.OrdinalIgnoreCase) is true) || (csb.SslKey?.EndsWith("ssl-client-key.pem", StringComparison.OrdinalIgnoreCase) is true)))
8686
return "Requires CertificateFile=client.pfx in connection string";
8787
}
8888

0 commit comments

Comments
 (0)