Skip to content

Commit d2ef02f

Browse files
committed
Various additional small cleanup
1 parent 2375707 commit d2ef02f

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

src/Npgsql/Internal/NpgsqlConnector.Auth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ async Task AuthenticateMD5(string username, byte[] salt, bool async, Cancellatio
322322
var resultString = sb.ToString();
323323
result = new byte[Encoding.UTF8.GetByteCount(resultString) + 1];
324324
Encoding.UTF8.GetBytes(resultString, 0, resultString.Length, result, 0);
325-
result[result.Length - 1] = 0;
325+
result[^1] = 0;
326326
}
327327

328328
await WritePassword(result, async, cancellationToken).ConfigureAwait(false);

src/Npgsql/Internal/NpgsqlConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,7 @@ void ReadParameterStatus(ReadOnlySpan<byte> incomingName, ReadOnlySpan<byte> inc
27722772

27732773
for (var i = 0; i < _rawParameters.Count; i++)
27742774
{
2775-
(var currentName, var currentValue) = _rawParameters[i];
2775+
var (currentName, currentValue) = _rawParameters[i];
27762776
if (incomingName.SequenceEqual(currentName))
27772777
{
27782778
if (incomingValue.SequenceEqual(currentValue))

src/Npgsql/NpgsqlDataReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ async Task<bool> NextResult(bool async, bool isConsuming = false, CancellationTo
502502
}
503503

504504
// There are no more queries, we're done. Read the RFQ.
505-
if (_statements.Count is 0 || !(_statements[_statements.Count - 1].AppendErrorBarrier ?? Command.EnableErrorBarriers))
505+
if (_statements.Count is 0 || !(_statements[^1].AppendErrorBarrier ?? Command.EnableErrorBarriers))
506506
Expect<ReadyForQueryMessage>(await Connector.ReadMessage(async).ConfigureAwait(false), Connector);
507507

508508
State = ReaderState.Consumed;

src/Npgsql/NpgsqlDataSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ internal virtual bool TryRentEnlistedPending(Transaction transaction, NpgsqlConn
447447
connector = null;
448448
return false;
449449
}
450-
connector = list[list.Count - 1];
450+
connector = list[^1];
451451
list.RemoveAt(list.Count - 1);
452452
if (list.Count == 0)
453453
_pendingEnlistedConnectors.Remove(transaction);

src/Npgsql/NpgsqlTypes/NpgsqlRange.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ public static NpgsqlRange<T> Parse(string value)
395395
if (!lowerInclusive && !lowerExclusive)
396396
throw new FormatException("Malformed range literal. Missing left parenthesis or bracket.");
397397

398-
var upperInclusive = value[value.Length - 1] == UpperInclusiveBound;
399-
var upperExclusive = value[value.Length - 1] == UpperExclusiveBound;
398+
var upperInclusive = value[^1] == UpperInclusiveBound;
399+
var upperExclusive = value[^1] == UpperExclusiveBound;
400400

401401
if (!upperInclusive && !upperExclusive)
402402
throw new FormatException("Malformed range literal. Missing right parenthesis or bracket.");

test/Npgsql.Tests/DataAdapterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public async Task Update_letting_null_field_falue()
304304
var dt = ds.Tables[0];
305305
Assert.IsNotNull(dt);
306306

307-
var dr = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1];
307+
var dr = ds.Tables[0].Rows[^1];
308308
dr["field_int2"] = 4;
309309

310310
var ds2 = ds.GetChanges()!;
@@ -350,7 +350,7 @@ public async Task DoUpdateWithDataSet()
350350
var dt = ds.Tables[0];
351351
Assert.IsNotNull(dt);
352352

353-
var dr = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1];
353+
var dr = ds.Tables[0].Rows[^1];
354354

355355
dr["field_int2"] = 4;
356356

test/Npgsql.Tests/ReaderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ public async Task GetBytes()
14001400
reader.GetBytes(4, 0, actual, 0, 2);
14011401
Assert.That(reader.GetBytes(4, expected.Length - 1, actual, 0, 2), Is.EqualTo(1),
14021402
"Length greater than data length");
1403-
Assert.That(actual[0], Is.EqualTo(expected[expected.Length - 1]), "Length greater than data length");
1403+
Assert.That(actual[0], Is.EqualTo(expected[^1]), "Length greater than data length");
14041404
Assert.That(() => reader.GetBytes(4, 0, actual, 0, actual.Length + 1),
14051405
Throws.Exception.TypeOf<IndexOutOfRangeException>(), "Length great than output buffer length");
14061406
// Close in the middle of a column
@@ -1662,7 +1662,7 @@ public async Task GetChars()
16621662
// Jump to another column from the middle of the column
16631663
reader.GetChars(5, 0, actual, 0, 2);
16641664
Assert.That(reader.GetChars(5, expected.Length - 1, actual, 0, 2), Is.EqualTo(1), "Length greater than data length");
1665-
Assert.That(actual[0], Is.EqualTo(expected[expected.Length - 1]), "Length greater than data length");
1665+
Assert.That(actual[0], Is.EqualTo(expected[^1]), "Length greater than data length");
16661666
Assert.That(() => reader.GetChars(5, 0, actual, 0, actual.Length + 1), Throws.Exception.TypeOf<IndexOutOfRangeException>(), "Length great than output buffer length");
16671667
// Close in the middle of a column
16681668
reader.GetChars(6, 0, actual, 0, 2);

0 commit comments

Comments
 (0)