Skip to content

Commit 1ed0351

Browse files
committed
Suppress CA2012 for safe uses of ValueTask.
ValueTask.GetAwaiter().GetResult() is only called on ValueTasks known to have completed synchronously.
1 parent 13a312a commit 1ed0351

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ public void FinishQuerying()
278278
// See https://bugs.mysql.com/bug.php?id=45679
279279
Log.Info("Session{0} sending 'DO SLEEP(0)' command to clear pending cancellation", m_logArguments);
280280
var payload = QueryPayload.Create("DO SLEEP(0);");
281+
#pragma warning disable CA2012 // Safe because method completes synchronously
281282
SendAsync(payload, IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
282283
payload = ReceiveReplyAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
284+
#pragma warning restore CA2012
283285
OkPayload.Create(payload.Span, SupportsDeprecateEof, SupportsSessionTrack);
284286
}
285287

src/MySqlConnector/MySqlBulkCopy.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public MySqlBulkCopy(MySqlConnection connection, MySqlTransaction? transaction =
102102
public void WriteToServer(DataTable dataTable)
103103
{
104104
m_valuesEnumerator = DataRowsValuesEnumerator.Create(dataTable ?? throw new ArgumentNullException(nameof(dataTable)));
105+
#pragma warning disable CA2012 // Safe because method completes synchronously
105106
WriteToServerAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
107+
#pragma warning restore CA2012
106108
}
107109

108110
#if NET45 || NET461 || NET471 || NETSTANDARD1_3 || NETSTANDARD2_0
@@ -140,7 +142,9 @@ public async ValueTask WriteToServerAsync(DataTable dataTable, CancellationToken
140142
public void WriteToServer(IEnumerable<DataRow> dataRows, int columnCount)
141143
{
142144
m_valuesEnumerator = new DataRowsValuesEnumerator(dataRows ?? throw new ArgumentNullException(nameof(dataRows)), columnCount);
145+
#pragma warning disable CA2012 // Safe because method completes synchronously
143146
WriteToServerAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
147+
#pragma warning restore CA2012
144148
}
145149
#if NET45 || NET461 || NET471 || NETSTANDARD1_3 || NETSTANDARD2_0
146150
/// <summary>
@@ -183,8 +187,11 @@ public async ValueTask WriteToServerAsync(IEnumerable<DataRow> dataRows, int col
183187
public void WriteToServer(IDataReader dataReader)
184188
{
185189
m_valuesEnumerator = DataReaderValuesEnumerator.Create(dataReader ?? throw new ArgumentNullException(nameof(dataReader)));
190+
#pragma warning disable CA2012 // Safe because method completes synchronously
186191
WriteToServerAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
192+
#pragma warning restore CA2012
187193
}
194+
188195
#if NET45 || NET461 || NET471 || NETSTANDARD1_3 || NETSTANDARD2_0
189196
/// <summary>
190197
/// Asynchronously copies all rows in the supplied <see cref="IDataReader"/> to the destination table specified by the

src/MySqlConnector/MySqlBulkLoader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ public MySqlBulkLoader(MySqlConnection connection)
149149
/// Loads all data in the source file or stream into the destination table.
150150
/// </summary>
151151
/// <returns>The number of rows inserted.</returns>
152+
#pragma warning disable CA2012 // Safe because method completes synchronously
152153
public int Load() => LoadAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
154+
#pragma warning restore CA2012
153155

154156
/// <summary>
155157
/// Asynchronously loads all data in the source file or stream into the destination table.

src/MySqlConnector/MySqlConnection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public MySqlConnection(string? connectionString)
3434
m_connectionString = connectionString ?? "";
3535
}
3636

37+
#pragma warning disable CA2012 // Safe because method completes synchronously
3738
/// <summary>
3839
/// Begins a database transaction.
3940
/// </summary>
@@ -64,6 +65,7 @@ public MySqlConnection(string? connectionString)
6465
/// <param name="isolationLevel">The <see cref="IsolationLevel"/> for the transaction.</param>
6566
/// <returns>A <see cref="MySqlTransaction"/> representing the new database transaction.</returns>
6667
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) => BeginTransactionAsync(isolationLevel, default, IOBehavior.Synchronous, default).GetAwaiter().GetResult();
68+
#pragma warning restore CA2012
6769

6870
#if NET45 || NET461 || NET471 || NETSTANDARD1_3 || NETSTANDARD2_0 || NETCOREAPP2_1
6971
/// <summary>
@@ -353,7 +355,9 @@ private async Task ChangeDatabaseAsync(IOBehavior ioBehavior, string databaseNam
353355

354356
public new MySqlCommand CreateCommand() => (MySqlCommand)base.CreateCommand();
355357

358+
#pragma warning disable CA2012 // Safe because method completes synchronously
356359
public bool Ping() => PingAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
360+
#pragma warning restore CA2012
357361
public Task<bool> PingAsync(CancellationToken cancellationToken = default) => PingAsync(SimpleAsyncIOBehavior, cancellationToken).AsTask();
358362

359363
private async ValueTask<bool> PingAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
@@ -524,6 +528,7 @@ private static async Task ClearPoolAsync(MySqlConnection connection, IOBehavior
524528
#if !NETSTANDARD1_3
525529
protected override DbProviderFactory DbProviderFactory => MySqlConnectorFactory.Instance;
526530

531+
#pragma warning disable CA2012 // Safe because method completes synchronously
527532
/// <summary>
528533
/// Returns schema information for the data source of this <see cref="MySqlConnection"/>.
529534
/// </summary>
@@ -544,6 +549,7 @@ private static async Task ClearPoolAsync(MySqlConnection connection, IOBehavior
544549
/// <param name="restrictionValues">The restrictions to apply to the schema; this parameter is currently ignored.</param>
545550
/// <returns>A <see cref="DataTable"/> containing schema information.</returns>
546551
public override DataTable GetSchema(string collectionName, string?[] restrictionValues) => GetSchemaProvider().GetSchemaAsync(IOBehavior.Synchronous, collectionName, default).GetAwaiter().GetResult();
552+
#pragma warning restore CA2012
547553

548554
/// <summary>
549555
/// Asynchronously returns schema information for the data source of this <see cref="MySqlConnection"/>.

src/MySqlConnector/MySqlDataReader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ public override long GetChars(int ordinal, long dataOffset, char[]? buffer, int
321321
return Task.FromResult(GetSchemaTable());
322322
}
323323

324+
#pragma warning disable CA2012 // Safe because method completes synchronously
324325
public override void Close() => DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
326+
#pragma warning restore CA2012
325327
#endif
326328

327329
/// <summary>
@@ -406,8 +408,10 @@ protected override void Dispose(bool disposing)
406408
{
407409
try
408410
{
411+
#pragma warning disable CA2012 // Safe because method completes synchronously
409412
if (disposing)
410413
DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
414+
#pragma warning restore CA2012
411415
}
412416
finally
413417
{

src/MySqlConnector/MySqlTransaction.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ protected override void Dispose(bool disposing)
180180
{
181181
try
182182
{
183+
#pragma warning disable CA2012 // Safe because method completes synchronously
183184
if (disposing)
184185
DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
186+
#pragma warning restore CA2012
185187
}
186188
finally
187189
{

0 commit comments

Comments
 (0)