Merge to patterns cleanup · npgsql/npgsql@2375707 · GitHub
Skip to content

Commit 2375707

Browse files
committed
Merge to patterns cleanup
1 parent a770d79 commit 2375707

8 files changed

Lines changed: 15 additions & 21 deletions

File tree

‎src/Npgsql/Internal/NpgsqlConnector.cs‎

Lines changed: 4 additions & 4 deletions

‎src/Npgsql/Internal/NpgsqlReadBuffer.cs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ async ValueTask<int> ReadWithTimeoutAsync(Memory<byte> buffer, CancellationToken
223223
// If we should attempt PostgreSQL cancellation, do it the first time we get a timeout.
224224
// TODO: As an optimization, we can still attempt to send a cancellation request, but after
225225
// that immediately break the connection
226-
if (connector.AttemptPostgresCancellation &&
227-
!connector.PostgresCancellationPerformed &&
226+
if (connector is { AttemptPostgresCancellation: true, PostgresCancellationPerformed: false } &&
228227
connector.PerformPostgresCancellation())
229228
{
230229
// Note that if the cancellation timeout is negative, we flow down and break the
@@ -350,8 +349,7 @@ static async ValueTask EnsureLong(
350349
// If we should attempt PostgreSQL cancellation, do it the first time we get a timeout.
351350
// TODO: As an optimization, we can still attempt to send a cancellation request, but after
352351
// that immediately break the connection
353-
if (connector.AttemptPostgresCancellation &&
354-
!connector.PostgresCancellationPerformed &&
352+
if (connector is { AttemptPostgresCancellation: true, PostgresCancellationPerformed: false } &&
355353
connector.PerformPostgresCancellation())
356354
{
357355
// Note that if the cancellation timeout is negative, we flow down and break the

‎src/Npgsql/NpgsqlBatchCommand.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ internal RowDescriptionMessage? Description
183183
/// </summary>
184184
internal PreparedStatement? PreparedStatement
185185
{
186-
get => _preparedStatement != null && _preparedStatement.State == PreparedState.Unprepared
186+
get => _preparedStatement is { State: PreparedState.Unprepared }
187187
? _preparedStatement = null
188188
: _preparedStatement;
189189
set => _preparedStatement = value;

‎src/Npgsql/NpgsqlCommand.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ internal void ProcessRawQuery(SqlQueryParser? parser, bool standardConformingStr
10311031

10321032
static void ValidateParameterCount(NpgsqlBatchCommand batchCommand)
10331033
{
1034-
if (batchCommand.HasParameters && batchCommand.PositionalParameters.Count > ushort.MaxValue)
1034+
if (batchCommand is { HasParameters: true, PositionalParameters.Count: > ushort.MaxValue })
10351035
ThrowHelper.ThrowNpgsqlException("A statement cannot have more than 65535 parameters");
10361036
}
10371037
}

‎src/Npgsql/NpgsqlRawCopyStream.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ async ValueTask DisposeAsync(bool disposing, bool async)
383383
}
384384
_connector.SkipUntil(BackendMessageCode.ReadyForQuery);
385385
}
386-
catch (OperationCanceledException e) when (e.InnerException is PostgresException pg && pg.SqlState == PostgresErrorCodes.QueryCanceled)
386+
catch (OperationCanceledException e) when (e.InnerException is PostgresException { SqlState: PostgresErrorCodes.QueryCanceled })
387387
{
388388
LogMessages.CopyOperationCancelled(_copyLogger, _connector.Id);
389389
}

‎src/Npgsql/NpgsqlTypes/NpgsqlTsVector.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static NpgsqlTsVector Parse(string value)
189189
if (value[pos] >= 'B' && value[pos] <= 'D' || value[pos] >= 'b' && value[pos] <= 'd')
190190
{
191191
var weight = value[pos];
192-
if (weight >= 'b' && weight <= 'd')
192+
if (weight is >= 'b' and <= 'd')
193193
weight = (char)(weight - ('b' - 'B'));
194194
wordEntryPositions.Add(new Lexeme.WordEntryPos(wordPos, Lexeme.Weight.D + ('D' - weight)));
195195
pos++;

‎test/Npgsql.Tests/CommandTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public async Task Timeout_from_connection_string()
243243
public async Task Timeout_switch_connection()
244244
{
245245
var csb = new NpgsqlConnectionStringBuilder(ConnectionString);
246-
if (csb.CommandTimeout >= 100 && csb.CommandTimeout < 105)
246+
if (csb.CommandTimeout is >= 100 and < 105)
247247
IgnoreExceptOnBuildServer("Bad default command timeout");
248248

249249
await using var dataSource1 = CreateDataSource(ConnectionString + ";CommandTimeout=100");

‎test/Npgsql.Tests/ConnectionTests.cs‎

Lines changed: 4 additions & 8 deletions

0 commit comments

Comments
 (0)