Skip to content

Commit f76ca36

Browse files
committed
Merge v1.3 into master.
Conflicts: src/MySqlConnector/Core/Row.cs src/MySqlConnector/Core/ServerSession.cs src/MySqlConnector/MySqlConnection.cs src/MySqlConnector/Protocol/Payloads/EofPayload.cs src/MySqlConnector/Protocol/Serialization/StreamByteHandler.cs src/MySqlConnector/Utilities/Utility.cs
2 parents ac7da01 + 813e309 commit f76ca36

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

src/MySqlConnector/Core/Row.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public Guid GetGuid(int ordinal)
170170
if (value is string stringValue && Guid.TryParse(stringValue, out guid))
171171
return guid;
172172

173-
if (value is byte[] bytes && bytes.Length == 16)
173+
if (value is byte[] { Length: 16 } bytes)
174174
return CreateGuidFromBytes(Connection.GuidFormat, bytes);
175175

176176
throw new InvalidCastException("The value could not be converted to a GUID: {0}".FormatInvariant(value));
@@ -421,7 +421,7 @@ public float GetFloat(int ordinal)
421421
// Use explicit range checks to guard against that.
422422
return value switch
423423
{
424-
double doubleValue => (doubleValue >= float.MinValue && doubleValue <= float.MaxValue ? (float) doubleValue : throw new InvalidCastException("The value cannot be safely cast to Single.")),
424+
double doubleValue => (doubleValue is >= float.MinValue and <= float.MaxValue ? (float) doubleValue : throw new InvalidCastException("The value cannot be safely cast to Single.")),
425425
decimal decimalValue => (float) decimalValue,
426426
_ => (float) value
427427
};

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ private async ValueTask<PayloadData> ReceiveReplyAsyncAwaited(ValueTask<ArraySeg
882882
catch (Exception ex)
883883
{
884884
SetFailed(ex);
885-
if (ex is MySqlException msex && msex.ErrorCode == MySqlErrorCode.CommandTimeoutExpired)
885+
if (ex is MySqlException { ErrorCode: MySqlErrorCode.CommandTimeoutExpired })
886886
HandleTimeout();
887887
throw;
888888
}
@@ -1009,11 +1009,11 @@ private async Task<bool> OpenTcpSocketAsync(ConnectionSettings cs, ILoadBalancer
10091009
}
10101010
}
10111011
}
1012-
catch (ObjectDisposedException ex) when (cancellationToken.IsCancellationRequested)
1012+
catch (ObjectDisposedException) when (cancellationToken.IsCancellationRequested)
10131013
{
10141014
SafeDispose(ref tcpClient);
10151015
Log.Info("Session{0} connect timeout expired connecting to IpAddress {1} for HostName '{2}'", m_logArguments[0], ipAddress, hostName);
1016-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.", ex);
1016+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.");
10171017
}
10181018
}
10191019
}
@@ -1066,10 +1066,10 @@ private async Task<bool> OpenUnixSocketAsync(ConnectionSettings cs, IOBehavior i
10661066
socket.Connect(unixEp);
10671067
}
10681068
}
1069-
catch (ObjectDisposedException ex) when (cancellationToken.IsCancellationRequested)
1069+
catch (ObjectDisposedException) when (cancellationToken.IsCancellationRequested)
10701070
{
10711071
Log.Info("Session{0} connect timeout expired connecting to UNIX Socket '{1}'", m_logArguments);
1072-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.", ex);
1072+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.");
10731073
}
10741074
}
10751075
}
@@ -1120,7 +1120,7 @@ private async Task<bool> OpenNamedPipeAsync(ConnectionSettings cs, int startTick
11201120
{
11211121
m_logArguments[1] = cs.PipeName;
11221122
Log.Info("Session{0} connect timeout expired connecting to named pipe '{1}'", m_logArguments);
1123-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.", ex);
1123+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.");
11241124
}
11251125
}
11261126
}
@@ -1382,7 +1382,7 @@ await sslStream.AuthenticateAsClientAsync(clientAuthenticationOptions.TargetHost
13821382
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "SSL Authentication Error", ex);
13831383
if (ex is IOException && clientCertificates is not null)
13841384
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "MySQL Server rejected client certificate", ex);
1385-
if (ex is Win32Exception win32 && win32.NativeErrorCode == -2146893007) // SEC_E_ALGORITHM_MISMATCH (0x80090331)
1385+
if (ex is Win32Exception { NativeErrorCode: -2146893007 }) // SEC_E_ALGORITHM_MISMATCH (0x80090331)
13861386
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "The server doesn't support the client's specified TLS versions.", ex);
13871387
throw;
13881388
}

src/MySqlConnector/MySqlConnection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,10 @@ internal async Task OpenAsync(IOBehavior? ioBehavior, CancellationToken cancella
408408
cancellationToken.ThrowIfCancellationRequested();
409409
throw;
410410
}
411-
catch (SocketException ex)
411+
catch (SocketException)
412412
{
413413
SetState(ConnectionState.Closed);
414-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Unable to connect to any of the specified MySQL hosts.", ex);
414+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Unable to connect to any of the specified MySQL hosts.");
415415
}
416416

417417
if (m_connectionSettings.AutoEnlist && System.Transactions.Transaction.Current is not null)
@@ -856,10 +856,10 @@ private async ValueTask<ServerSession> CreateSessionAsync(ConnectionPool? pool,
856856
return session;
857857
}
858858
}
859-
catch (OperationCanceledException ex) when (timeoutSource?.IsCancellationRequested ?? false)
859+
catch (OperationCanceledException) when (timeoutSource?.IsCancellationRequested ?? false)
860860
{
861861
var messageSuffix = (pool?.IsEmpty ?? false) ? " All pooled connections are in use." : "";
862-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired." + messageSuffix, ex);
862+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired." + messageSuffix);
863863
}
864864
catch (MySqlException ex) when ((timeoutSource?.IsCancellationRequested ?? false) || (ex.ErrorCode == MySqlErrorCode.CommandTimeoutExpired))
865865
{

src/MySqlConnector/Protocol/Payloads/EofPayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static EofPayload Create(ReadOnlySpan<byte> span)
3030
/// <param name="payload">The payload to examine.</param>
3131
/// <returns><c>true</c> if this is an EOF packet; otherwise, <c>false</c>.</returns>
3232
public static bool IsEof(PayloadData payload) =>
33-
payload.Span.Length > 0 && payload.Span.Length < 9 && payload.HeaderByte == Signature;
33+
payload.Span.Length is > 0 and < 9 && payload.HeaderByte == Signature;
3434

3535
public const byte Signature = 0xFE;
3636

src/MySqlConnector/Protocol/Serialization/StreamByteHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ValueTask<int> DoReadBytesSync(Memory<byte> buffer)
3838
}
3939
catch (Exception ex)
4040
{
41-
if (RemainingTimeout != Constants.InfiniteTimeout && ex is IOException ioException && ioException.InnerException is SocketException socketException && socketException.SocketErrorCode == SocketError.TimedOut)
41+
if (RemainingTimeout != Constants.InfiniteTimeout && ex is IOException { InnerException: SocketException { SocketErrorCode: SocketError.TimedOut } })
4242
return ValueTaskExtensions.FromException<int>(MySqlException.CreateForTimeout(ex));
4343
return ValueTaskExtensions.FromException<int>(ex);
4444
}

src/MySqlConnector/Utilities/Utility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ public static SslProtocols GetDefaultSslProtocols()
620620
try
621621
{
622622
var property = typeof(ServicePointManager).GetProperty("DisableSystemDefaultTlsVersions", BindingFlags.NonPublic | BindingFlags.Static);
623-
disableSystemDefaultTlsVersions = property is null || (property.GetValue(null) is bool b && b);
623+
disableSystemDefaultTlsVersions = property is null || property.GetValue(null) is true;
624624
}
625625
catch (Exception)
626626
{

0 commit comments

Comments
 (0)