Skip to content

Commit 466cf37

Browse files
committed
Use 'is null' to test for null.
1 parent dd4718a commit 466cf37

35 files changed

+100
-104
lines changed

src/MySqlConnector.Logging.Microsoft.Extensions.Logging/MicrosoftExtensionsLoggingLoggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private class MicrosoftExtensionsLoggingLogger : IMySqlConnectorLogger
1818

1919
public void Log(MySqlConnectorLogLevel level, string message, object[] args = null, Exception exception = null)
2020
{
21-
if (args == null || args.Length == 0)
21+
if (args is null || args.Length == 0)
2222
m_logger.Log(GetLevel(level), 0, message, exception, s_getMessage);
2323
else
2424
m_logger.Log(GetLevel(level), 0, (message, args), exception, s_messageFormatter);

src/MySqlConnector.Logging.Serilog/SerilogLoggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public SerilogLogger(string name)
2626

2727
public void Log(MySqlConnectorLogLevel level, string message, object[] args = null, Exception exception = null)
2828
{
29-
if (args == null || args.Length == 0)
29+
if (args is null || args.Length == 0)
3030
m_logger.Write(GetLevel(level), exception, message);
3131
else
3232
{

src/MySqlConnector.Logging.log4net/Log4netLoggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private class Log4netLogger : IMySqlConnectorLogger
2121

2222
public void Log(MySqlConnectorLogLevel level, string message, object[] args = null, Exception exception = null)
2323
{
24-
if (args == null || args.Length == 0)
24+
if (args is null || args.Length == 0)
2525
m_logger.Log(s_loggerType, GetLevel(level), message, exception);
2626
else
2727
m_logger.Log(s_loggerType, GetLevel(level), string.Format(CultureInfo.InvariantCulture, message, args), exception);

src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public async Task ReapAsync(IOBehavior ioBehavior, CancellationToken cancellatio
214214
public Dictionary<string, CachedProcedure> GetProcedureCache()
215215
{
216216
var procedureCache = m_procedureCache;
217-
if (procedureCache == null)
217+
if (procedureCache is null)
218218
{
219219
var newProcedureCache = new Dictionary<string, CachedProcedure>();
220220
procedureCache = Interlocked.CompareExchange(ref m_procedureCache, newProcedureCache, null) ?? newProcedureCache;
@@ -290,7 +290,7 @@ private async Task CleanPoolAsync(IOBehavior ioBehavior, Func<ServerSession, boo
290290
m_sessions.RemoveLast();
291291
}
292292
}
293-
if (session == null)
293+
if (session is null)
294294
return;
295295

296296
if (shouldCleanFn(session))

src/MySqlConnector/Core/DbTypeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public object DoConversion(object obj)
1919
{
2020
if (obj.GetType() == ClrType)
2121
return obj;
22-
return m_convert == null ? Convert.ChangeType(obj, ClrType) : m_convert(obj);
22+
return m_convert is null ? Convert.ChangeType(obj, ClrType) : m_convert(obj);
2323
}
2424

2525
readonly Func<object, object> m_convert;

src/MySqlConnector/Core/NormalizedSchema.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ internal sealed class NormalizedSchema
1616
internal static NormalizedSchema MustNormalize(string name, string defaultSchema = null)
1717
{
1818
var normalized = new NormalizedSchema(name, defaultSchema);
19-
if (normalized.Component == null)
19+
if (normalized.Component is null)
2020
throw new ArgumentException("Could not determine function/procedure name", nameof(name));
21-
if (normalized.Schema == null)
21+
if (normalized.Schema is null)
2222
throw new ArgumentException("Could not determine schema", nameof(defaultSchema));
2323
return normalized;
2424
}
@@ -38,12 +38,12 @@ public NormalizedSchema(string name, string defaultSchema=null)
3838
firstGroup = match.Groups[1].Value.Trim();
3939
else if (match.Groups[2].Success)
4040
firstGroup = match.Groups[2].Value.Trim();
41-
if (Component == null)
41+
if (Component is null)
4242
Component = firstGroup.Trim();
4343
else
4444
Schema = firstGroup.Trim();
4545

46-
if (Schema == null)
46+
if (Schema is null)
4747
Schema = defaultSchema;
4848
}
4949
}

src/MySqlConnector/Core/PreparedStatementCommandExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private PayloadData CreateQueryPayload(PreparedStatement preparedStatement, MySq
8080
for (var i = 0; i < parameters.Length; i++)
8181
{
8282
var parameter = parameters[i];
83-
if (parameter.Value == null || parameter.Value == DBNull.Value)
83+
if (parameter.Value is null || parameter.Value == DBNull.Value)
8484
nullBitmap |= (byte) (1 << (i % 8));
8585

8686
if (i % 8 == 7)

src/MySqlConnector/Core/ResultSet.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public async Task<bool> ReadAsync(IOBehavior ioBehavior, CancellationToken cance
174174
? m_readBuffer.Dequeue()
175175
: await ScanRowAsync(ioBehavior, m_row, cancellationToken).ConfigureAwait(false);
176176

177-
if (m_row == null)
177+
if (m_row is null)
178178
{
179179
State = BufferState;
180180
return false;
@@ -187,7 +187,7 @@ public async Task<Row> BufferReadAsync(IOBehavior ioBehavior, CancellationToken
187187
{
188188
m_rowBuffered = m_rowBuffered?.Clone();
189189
// ScanRowAsync sets m_rowBuffered to the next row if there is one
190-
if (await ScanRowAsync(ioBehavior, null, cancellationToken).ConfigureAwait(false) == null)
190+
if (await ScanRowAsync(ioBehavior, null, cancellationToken).ConfigureAwait(false) is null)
191191
return null;
192192
m_readBuffer.Enqueue(m_rowBuffered);
193193
return m_rowBuffered;
@@ -245,7 +245,7 @@ Row ScanRowAsyncRemainder(PayloadData payload, Row row_)
245245
}
246246
}
247247

248-
if (row_ == null)
248+
if (row_ is null)
249249
row_ = DataReader.ResultSetProtocol == ResultSetProtocol.Binary ? (Row) new BinaryRow(this) : new TextRow(this);
250250
row_.SetData(payload.ArraySegment);
251251
m_rowBuffered = row_;
@@ -259,7 +259,7 @@ Row ScanRowAsyncRemainder(PayloadData payload, Row row_)
259259

260260
public string GetName(int ordinal)
261261
{
262-
if (ColumnDefinitions == null)
262+
if (ColumnDefinitions is null)
263263
throw new InvalidOperationException("There is no current result set.");
264264
if (ordinal < 0 || ordinal >= ColumnDefinitions.Length)
265265
throw new IndexOutOfRangeException("value must be between 0 and {0}".FormatInvariant(ColumnDefinitions.Length - 1));
@@ -268,7 +268,7 @@ public string GetName(int ordinal)
268268

269269
public string GetDataTypeName(int ordinal)
270270
{
271-
if (ColumnDefinitions == null)
271+
if (ColumnDefinitions is null)
272272
throw new InvalidOperationException("There is no current result set.");
273273
if (ordinal < 0 || ordinal >= ColumnDefinitions.Length)
274274
throw new IndexOutOfRangeException("value must be between 0 and {0}.".FormatInvariant(ColumnDefinitions.Length));
@@ -281,7 +281,7 @@ public string GetDataTypeName(int ordinal)
281281

282282
public Type GetFieldType(int ordinal)
283283
{
284-
if (ColumnDefinitions == null)
284+
if (ColumnDefinitions is null)
285285
throw new InvalidOperationException("There is no current result set.");
286286
if (ordinal < 0 || ordinal >= ColumnDefinitions.Length)
287287
throw new IndexOutOfRangeException("value must be between 0 and {0}.".FormatInvariant(ColumnDefinitions.Length));
@@ -306,9 +306,9 @@ public bool HasRows
306306

307307
public int GetOrdinal(string name)
308308
{
309-
if (name == null)
309+
if (name is null)
310310
throw new ArgumentNullException(nameof(name));
311-
if (ColumnDefinitions == null)
311+
if (ColumnDefinitions is null)
312312
throw new InvalidOperationException("There is no current result set.");
313313

314314
for (var column = 0; column < ColumnDefinitions.Length; column++)

src/MySqlConnector/Core/Row.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal abstract class Row
1313
public void SetData(ArraySegment<byte> data)
1414
{
1515
m_data = data;
16-
if (m_dataOffsets == null)
16+
if (m_dataOffsets is null)
1717
{
1818
m_dataOffsets = new int[ResultSet.ColumnDefinitions.Length];
1919
m_dataLengths = new int[ResultSet.ColumnDefinitions.Length];
@@ -76,7 +76,7 @@ public long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffs
7676
{
7777
CheckBinaryColumn(ordinal);
7878

79-
if (buffer == null)
79+
if (buffer is null)
8080
{
8181
// this isn't required by the DbDataReader.GetBytes API documentation, but is what mysql-connector-net does
8282
// (as does SqlDataReader: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getbytes.aspx)
@@ -100,7 +100,7 @@ public char GetChar(int ordinal)
100100
public long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
101101
{
102102
var value = GetString(ordinal);
103-
if (buffer == null)
103+
if (buffer is null)
104104
return value.Length;
105105

106106
CheckBufferArguments(dataOffset, buffer, bufferOffset, length);

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void AbortCancel(MySqlCommand command)
131131

132132
public void AddPreparedStatement(string commandText, PreparedStatements preparedStatements)
133133
{
134-
if (m_preparedStatements == null)
134+
if (m_preparedStatements is null)
135135
m_preparedStatements = new Dictionary<string, PreparedStatements>();
136136
m_preparedStatements.Add(commandText, preparedStatements);
137137
}
@@ -284,7 +284,7 @@ public async Task ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer
284284
throw new MySqlException((int) MySqlErrorCode.UnableToConnectToHost, null, "Unable to connect to any of the specified MySQL hosts.");
285285
}
286286

287-
var byteHandler = m_socket != null ? (IByteHandler) new SocketByteHandler(m_socket) : new StreamByteHandler(m_stream);
287+
var byteHandler = m_socket is null ? new StreamByteHandler(m_stream) : (IByteHandler) new SocketByteHandler(m_socket);
288288
m_payloadHandler = new StandardPayloadHandler(byteHandler);
289289

290290
payload = await ReceiveAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
@@ -352,7 +352,7 @@ public async Task ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer
352352
}
353353
} while (shouldRetrySsl);
354354

355-
if (m_supportsConnectionAttributes && cs.ConnectionAttributes == null)
355+
if (m_supportsConnectionAttributes && cs.ConnectionAttributes is null)
356356
cs.ConnectionAttributes = CreateConnectionAttributes(cs.ApplicationName);
357357

358358
using (var handshakeResponsePayload = HandshakeResponse41Payload.Create(initialHandshake, cs, m_useCompression, m_characterSet, m_supportsConnectionAttributes ? cs.ConnectionAttributes : null))
@@ -394,7 +394,7 @@ public async Task<bool> TryResetConnectionAsync(ConnectionSettings cs, IOBehavio
394394
// clear all prepared statements; resetting the connection will clear them on the server
395395
ClearPreparedStatements();
396396

397-
if (DatabaseOverride == null && (ServerVersion.Version.CompareTo(ServerVersions.SupportsResetConnection) >= 0 || ServerVersion.MariaDbVersion?.CompareTo(ServerVersions.MariaDbSupportsResetConnection) >= 0))
397+
if (DatabaseOverride is null && (ServerVersion.Version.CompareTo(ServerVersions.SupportsResetConnection) >= 0 || ServerVersion.MariaDbVersion?.CompareTo(ServerVersions.MariaDbSupportsResetConnection) >= 0))
398398
{
399399
m_logArguments[1] = ServerVersion.OriginalString;
400400
Log.Debug("Session{0} ServerVersion={1} supports reset connection; sending reset connection request", m_logArguments);
@@ -410,7 +410,7 @@ public async Task<bool> TryResetConnectionAsync(ConnectionSettings cs, IOBehavio
410410
else
411411
{
412412
// optimistically hash the password with the challenge from the initial handshake (supported by MariaDB; doesn't appear to be supported by MySQL)
413-
if (DatabaseOverride == null)
413+
if (DatabaseOverride is null)
414414
{
415415
m_logArguments[1] = ServerVersion.OriginalString;
416416
Log.Debug("Session{0} ServerVersion={1} doesn't support reset connection; sending change user request", m_logArguments);
@@ -918,7 +918,7 @@ private async Task InitSslAsync(ProtocolCapabilities serverCapabilities, Connect
918918
var store = new X509Store(StoreName.My, storeLocation);
919919
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
920920

921-
if (cs.CertificateThumbprint == null)
921+
if (cs.CertificateThumbprint is null)
922922
{
923923
if (store.Certificates.Count == 0)
924924
{
@@ -1064,11 +1064,8 @@ bool ValidateRemoteCertificate(object rcbSender, X509Certificate rcbCertificate,
10641064
return rcbPolicyErrors == SslPolicyErrors.None;
10651065
}
10661066

1067-
SslStream sslStream;
1068-
if (clientCertificates == null)
1069-
sslStream = new SslStream(m_stream, false, ValidateRemoteCertificate);
1070-
else
1071-
sslStream = new SslStream(m_stream, false, ValidateRemoteCertificate, ValidateLocalCertificate);
1067+
var sslStream = clientCertificates is null ? new SslStream(m_stream, false, ValidateRemoteCertificate) :
1068+
new SslStream(m_stream, false, ValidateRemoteCertificate, ValidateLocalCertificate);
10721069

10731070
var checkCertificateRevocation = cs.SslMode == MySqlSslMode.VerifyFull;
10741071

0 commit comments

Comments
 (0)