Skip to content

Commit a8dfa48

Browse files
committed
Use 'is not null' instead of 'is object'.
1 parent 9993386 commit a8dfa48

30 files changed

+99
-99
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<RepositoryType>git</RepositoryType>
1515
<RepositoryUrl>https://github.com/mysql-net/MySqlConnector.git</RepositoryUrl>
1616
<DebugType>embedded</DebugType>
17-
<LangVersion>8.0</LangVersion>
17+
<LangVersion>preview</LangVersion>
1818
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1919
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2020
<GenerateDocumentationFile>true</GenerateDocumentationFile>

src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
5555
m_sessions.RemoveFirst();
5656
}
5757
}
58-
if (session is object)
58+
if (session is not null)
5959
{
6060
Log.Debug("Pool{0} found an existing session; checking it for validity", m_logArguments);
6161
bool reuseSession;
@@ -67,7 +67,7 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
6767
}
6868
else
6969
{
70-
if (ConnectionSettings.ConnectionReset || session.DatabaseOverride is object)
70+
if (ConnectionSettings.ConnectionReset || session.DatabaseOverride is not null)
7171
{
7272
reuseSession = await session.TryResetConnectionAsync(ConnectionSettings, ioBehavior, cancellationToken).ConfigureAwait(false);
7373
}
@@ -123,7 +123,7 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
123123
}
124124
catch (Exception ex)
125125
{
126-
if (session is object)
126+
if (session is not null)
127127
{
128128
try
129129
{
@@ -435,7 +435,7 @@ private static IReadOnlyList<ConnectionPool> GetAllPools()
435435
var uniquePools = new HashSet<ConnectionPool>();
436436
foreach (var pool in s_pools.Values)
437437
{
438-
if (pool is object && uniquePools.Add(pool))
438+
if (pool is not null && uniquePools.Add(pool))
439439
pools.Add(pool);
440440
}
441441
return pools;
@@ -496,7 +496,7 @@ private void StartReaperTask()
496496

497497
private void AdjustHostConnectionCount(ServerSession session, int delta)
498498
{
499-
if (m_hostSessions is object)
499+
if (m_hostSessions is not null)
500500
{
501501
lock (m_hostSessions)
502502
m_hostSessions[session.HostName] += delta;

src/MySqlConnector/Core/ResultSet.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task ReadResultSetHeaderAsync(IOBehavior ioBehavior)
5757
RecordsAffected = (RecordsAffected ?? 0) + ok.AffectedRowCount;
5858
LastInsertId = unchecked((long) ok.LastInsertId);
5959
WarningCount = ok.WarningCount;
60-
if (ok.NewSchema is object)
60+
if (ok.NewSchema is not null)
6161
Connection.Session.DatabaseOverride = ok.NewSchema;
6262
ColumnDefinitions = null;
6363
ColumnTypes = null;
@@ -201,7 +201,7 @@ public async Task<bool> ReadAsync(IOBehavior ioBehavior, CancellationToken cance
201201
m_row = m_readBuffer?.Count > 0 ? m_readBuffer.Dequeue() :
202202
await ScanRowAsync(ioBehavior, m_row, cancellationToken).ConfigureAwait(false);
203203

204-
if (Command.ReturnParameter is object && m_row is object)
204+
if (Command.ReturnParameter is not null && m_row is not null)
205205
{
206206
Command.ReturnParameter.Value = m_row.GetValue(0);
207207
Command.ReturnParameter = null;
@@ -394,7 +394,7 @@ public bool HasRows
394394
get
395395
{
396396
if (BufferState == ResultSetState.ReadResultSetHeader)
397-
return BufferReadAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult() is object;
397+
return BufferReadAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult() is not null;
398398
return m_hasRows;
399399
}
400400
}

src/MySqlConnector/Core/SchemaProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ private void FillColumns(DataTable dataTable)
188188

189189
using (var command = new MySqlCommand("SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'information_schema' AND table_name = 'COLUMNS' AND column_name = 'GENERATION_EXPRESSION';", m_connection))
190190
{
191-
if (command.ExecuteScalar() is object)
191+
if (command.ExecuteScalar() is not null)
192192
dataTable.Columns.Add(new DataColumn("GENERATION_EXPRESSION", typeof(string))); // lgtm[cs/local-not-disposed]
193193
}
194194

195195
using (var command = new MySqlCommand("SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'information_schema' AND table_name = 'COLUMNS' AND column_name = 'SRS_ID';", m_connection))
196196
{
197-
if (command.ExecuteScalar() is object)
197+
if (command.ExecuteScalar() is not null)
198198
dataTable.Columns.Add(new DataColumn("SRS_ID", typeof(uint))); // lgtm[cs/local-not-disposed]
199199
}
200200

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public async Task PrepareAsync(IMySqlCommand command, IOBehavior ioBehavior, Can
231231

232232
public PreparedStatements? TryGetPreparedStatement(string commandText)
233233
{
234-
if (m_preparedStatements is object)
234+
if (m_preparedStatements is not null)
235235
{
236236
if (m_preparedStatements.TryGetValue(commandText, out var statement))
237237
return statement;
@@ -298,7 +298,7 @@ public void FinishQuerying()
298298

299299
public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
300300
{
301-
if (m_payloadHandler is object)
301+
if (m_payloadHandler is not null)
302302
{
303303
// attempt to gracefully close the connection, ignoring any errors (it may have been closed already by the server, etc.)
304304
State state;
@@ -440,7 +440,7 @@ public async Task ConnectAsync(ConnectionSettings cs, int startTickCount, ILoadB
440440
// negotiating TLS 1.2 with a yaSSL-based server throws an exception on Windows, see comment at top of method
441441
Log.Warn(ex, "Session{0} failed negotiating TLS; falling back to TLS 1.1", m_logArguments);
442442
sslProtocols = SslProtocols.Tls | SslProtocols.Tls11;
443-
if (Pool is object)
443+
if (Pool is not null)
444444
Pool.SslProtocols = sslProtocols;
445445
}
446446
}
@@ -842,7 +842,7 @@ private async ValueTask<int> SendReplyAsyncAwaited(ValueTask<int> task)
842842

843843
internal void HandleTimeout()
844844
{
845-
if (OwningConnection is object && OwningConnection.TryGetTarget(out var connection))
845+
if (OwningConnection is not null && OwningConnection.TryGetTarget(out var connection))
846846
connection.SetState(ConnectionState.Closed);
847847
}
848848

@@ -1109,7 +1109,7 @@ private async Task InitSslAsync(ProtocolCapabilities serverCapabilities, Connect
11091109
}
11101110
}
11111111

1112-
if (cs.SslCertificateFile is object && cs.SslKeyFile is object)
1112+
if (cs.SslCertificateFile is not null && cs.SslKeyFile is not null)
11131113
{
11141114
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
11151115
m_logArguments[1] = cs.SslKeyFile;
@@ -1183,7 +1183,7 @@ private async Task InitSslAsync(ProtocolCapabilities serverCapabilities, Connect
11831183
throw new NotSupportedException("SslCert and SslKey connection string options are not supported in netstandard1.3 or netstandard2.0.");
11841184
#endif
11851185
}
1186-
else if (cs.CertificateFile is object)
1186+
else if (cs.CertificateFile is not null)
11871187
{
11881188
try
11891189
{
@@ -1209,7 +1209,7 @@ private async Task InitSslAsync(ProtocolCapabilities serverCapabilities, Connect
12091209
}
12101210

12111211
X509Chain? caCertificateChain = null;
1212-
if (cs.CACertificateFile is object)
1212+
if (cs.CACertificateFile is not null)
12131213
{
12141214
X509Chain? certificateChain = new X509Chain
12151215
{
@@ -1281,7 +1281,7 @@ bool ValidateRemoteCertificate(object rcbSender, X509Certificate rcbCertificate,
12811281
if (cs.SslMode == MySqlSslMode.Preferred || cs.SslMode == MySqlSslMode.Required)
12821282
return true;
12831283

1284-
if ((rcbPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0 && caCertificateChain is object)
1284+
if ((rcbPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0 && caCertificateChain is not null)
12851285
{
12861286
if (caCertificateChain.Build((X509Certificate2) rcbCertificate) && caCertificateChain.ChainStatus.Length > 0)
12871287
{
@@ -1336,7 +1336,7 @@ bool ValidateRemoteCertificate(object rcbSender, X509Certificate rcbCertificate,
13361336
m_state = State.Failed;
13371337
if (ex is AuthenticationException)
13381338
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "SSL Authentication Error", ex);
1339-
if (ex is IOException && clientCertificates is object)
1339+
if (ex is IOException && clientCertificates is not null)
13401340
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "MySQL Server rejected client certificate", ex);
13411341
if (ex is Win32Exception win32 && win32.NativeErrorCode == -2146893007) // SEC_E_ALGORITHM_MISMATCH (0x80090331)
13421342
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "The server doesn't support the client's specified TLS versions.", ex);
@@ -1411,7 +1411,7 @@ static void ReadRow(ReadOnlySpan<byte> span, out int? connectionId_, out byte[]?
14111411
else
14121412
EofPayload.Create(payload.Span);
14131413

1414-
if (connectionId.HasValue && serverVersion is object)
1414+
if (connectionId.HasValue && serverVersion is not null)
14151415
{
14161416
var newServerVersion = new ServerVersion(serverVersion);
14171417
Log.Info("Session{0} changing ConnectionIdOld {1} to ConnectionId {2} and ServerVersionOld {3} to ServerVersion {4}", m_logArguments[0], ConnectionId, connectionId.Value, ServerVersion.OriginalString, newServerVersion.OriginalString);
@@ -1449,7 +1449,7 @@ private void ShutdownSocket()
14491449
private static void SafeDispose<T>(ref T? disposable)
14501450
where T : class, IDisposable
14511451
{
1452-
if (disposable is object)
1452+
if (disposable is not null)
14531453
{
14541454
try
14551455
{
@@ -1471,7 +1471,7 @@ internal void SetFailed(Exception exception)
14711471
Log.Info(exception, "Session{0} setting state to Failed", m_logArguments);
14721472
lock (m_lock)
14731473
m_state = State.Failed;
1474-
if (OwningConnection is object && OwningConnection.TryGetTarget(out var connection))
1474+
if (OwningConnection is not null && OwningConnection.TryGetTarget(out var connection))
14751475
connection.SetState(ConnectionState.Closed);
14761476
}
14771477

@@ -1529,7 +1529,7 @@ private byte[] CreateConnectionAttributes(string? programName)
15291529
try
15301530
{
15311531
Utility.GetOSDetails(out var os, out var osDescription, out var architecture);
1532-
if (os is object)
1532+
if (os is not null)
15331533
{
15341534
attributesWriter.WriteLengthEncodedString("_os");
15351535
attributesWriter.WriteLengthEncodedString(os);
@@ -1569,7 +1569,7 @@ private Exception CreateExceptionForErrorPayload(ReadOnlySpan<byte> span)
15691569

15701570
private void ClearPreparedStatements()
15711571
{
1572-
if (m_preparedStatements is object)
1572+
if (m_preparedStatements is not null)
15731573
{
15741574
foreach (var pair in m_preparedStatements)
15751575
pair.Value.Dispose();

src/MySqlConnector/Core/SingleCommandPayloadCreator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ private static void WritePreparedStatement(IMySqlCommand command, PreparedStatem
7878
for (var i = 0; i < preparedStatement.Statement.ParameterNames.Count; i++)
7979
{
8080
var parameterName = preparedStatement.Statement.ParameterNames[i];
81-
var parameterIndex = parameterName is object ? (parameterCollection?.NormalizedIndexOf(parameterName) ?? -1) : preparedStatement.Statement.ParameterIndexes[i];
82-
if (parameterIndex == -1 && parameterName is object)
81+
var parameterIndex = parameterName is not null ? (parameterCollection?.NormalizedIndexOf(parameterName) ?? -1) : preparedStatement.Statement.ParameterIndexes[i];
82+
if (parameterIndex == -1 && parameterName is not null)
8383
throw new MySqlException("Parameter '{0}' must be defined.".FormatInvariant(parameterName));
8484
else if (parameterIndex < 0 || parameterIndex >= (parameterCollection?.Count ?? 0))
8585
throw new MySqlException("Parameter index {0} is invalid when only {1} parameter{2} defined.".FormatInvariant(parameterIndex, parameterCollection?.Count ?? 0, parameterCollection?.Count == 1 ? " is" : "s are"));
@@ -111,7 +111,7 @@ private static void WritePreparedStatement(IMySqlCommand command, PreparedStatem
111111
// override explicit MySqlDbType with inferred type from the Value
112112
var mySqlDbType = parameter.MySqlDbType;
113113
var typeMapping = (parameter.Value is null || parameter.Value == DBNull.Value) ? null : TypeMapper.Instance.GetDbTypeMapping(parameter.Value.GetType());
114-
if (typeMapping is object)
114+
if (typeMapping is not null)
115115
{
116116
var dbType = typeMapping.DbTypes[0];
117117
mySqlDbType = TypeMapper.Instance.GetMySqlDbTypeForDbType(dbType);
@@ -130,7 +130,7 @@ private static bool WriteStoredProcedure(IMySqlCommand command, IDictionary<stri
130130
{
131131
var parameterCollection = command.RawParameters;
132132
var cachedProcedure = cachedProcedures[command.CommandText!];
133-
if (cachedProcedure is object)
133+
if (cachedProcedure is not null)
134134
parameterCollection = cachedProcedure.AlignParamsWithDb(parameterCollection);
135135

136136
MySqlParameter? returnParameter = null;

src/MySqlConnector/Core/TypeMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private DbTypeMapping AddDbTypeMapping(DbTypeMapping dbTypeMapping)
132132
{
133133
m_dbTypeMappingsByClrType[dbTypeMapping.ClrType] = dbTypeMapping;
134134

135-
if (dbTypeMapping.DbTypes is object)
135+
if (dbTypeMapping.DbTypes is not null)
136136
foreach (var dbType in dbTypeMapping.DbTypes)
137137
m_dbTypeMappingsByDbType[dbType] = dbTypeMapping;
138138

src/MySqlConnector/Logging/ConsoleLoggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Log(MySqlConnectorLogLevel level, string message, object?[]? args =
4444
sb.AppendFormat(CultureInfo.InvariantCulture, message, args);
4545
sb.AppendLine();
4646

47-
if (exception is object)
47+
if (exception is not null)
4848
sb.AppendLine(exception.ToString());
4949

5050
if (m_provider.m_isColored)

src/MySqlConnector/MySql.Data.MySqlClient/MySqlBatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void Prepare()
7171
{
7272
if (!NeedsPrepare(out var exception))
7373
{
74-
if (exception is object)
74+
if (exception is not null)
7575
throw exception;
7676
return;
7777
}

src/MySqlConnector/MySql.Data.MySqlClient/MySqlBulkCopy.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
205205
bulkLoader.Columns.Add(columnMapping.DestinationColumn);
206206
else
207207
bulkLoader.Columns.Add(QuoteIdentifier(columnMapping.DestinationColumn));
208-
if (columnMapping.Expression is object)
208+
if (columnMapping.Expression is not null)
209209
bulkLoader.Expressions.Add(columnMapping.Expression);
210210
}
211211
}
@@ -239,9 +239,9 @@ static void AddColumnMapping(List<MySqlBulkCopyColumnMapping> columnMappings, bo
239239
{
240240
expression = expression.Replace("%COL%", "`" + destinationColumn + "`").Replace("%VAR%", variableName);
241241
var columnMapping = columnMappings.FirstOrDefault(x => destinationColumn.Equals(x.DestinationColumn, StringComparison.OrdinalIgnoreCase));
242-
if (columnMapping is object)
242+
if (columnMapping is not null)
243243
{
244-
if (columnMapping.Expression is object)
244+
if (columnMapping.Expression is not null)
245245
{
246246
Log.Warn("Column mapping for SourceOrdinal {0}, DestinationColumn {1} already has Expression {2}", columnMapping.SourceOrdinal, destinationColumn, columnMapping.Expression);
247247
}
@@ -270,7 +270,7 @@ internal async Task SendDataReaderAsync(IOBehavior ioBehavior, CancellationToken
270270
// allocate a reusable MySqlRowsCopiedEventArgs if event notification is necessary
271271
RowsCopied = 0;
272272
MySqlRowsCopiedEventArgs? eventArgs = null;
273-
if (NotifyAfter > 0 && MySqlRowsCopied is object)
273+
if (NotifyAfter > 0 && MySqlRowsCopied is not null)
274274
eventArgs = new MySqlRowsCopiedEventArgs();
275275

276276
try
@@ -318,7 +318,7 @@ await m_valuesEnumerator.MoveNextAsync().ConfigureAwait(false) :
318318
buffer[outputIndex++] = (byte) '\n';
319319

320320
RowsCopied++;
321-
if (eventArgs is object && RowsCopied % NotifyAfter == 0)
321+
if (eventArgs is not null && RowsCopied % NotifyAfter == 0)
322322
{
323323
eventArgs.RowsCopied = RowsCopied;
324324
MySqlRowsCopied!(this, eventArgs);

0 commit comments

Comments
 (0)