Skip to content

Commit e540584

Browse files
elachlansharwell
andauthored
CA1835 Prefer the 'Memory'-based overloads for 'ReadAsync' and 'Write… (#7184)
* CA1835 Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' * Update src/Shared/CommunicationsUtilities.cs Co-authored-by: Sam Harwell <sam@tunnelvisionlabs.com> * Revert CodeAnalysis.ruleset * enable warning on CA1835 Co-authored-by: Sam Harwell <sam@tunnelvisionlabs.com>
1 parent cefeea2 commit e540584

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

eng/Common.globalconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ dotnet_diagnostic.CA1833.severity = warning
310310
dotnet_diagnostic.CA1834.severity = suggestion
311311

312312
# Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'
313-
dotnet_diagnostic.CA1835.severity = suggestion
313+
dotnet_diagnostic.CA1835.severity = warning
314314

315315
# Prefer IsEmpty over Count
316316
dotnet_diagnostic.CA1836.severity = suggestion

src/Shared/CommunicationsUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ internal static async Task<int> ReadAsync(Stream stream, byte[] buffer, int byte
465465
int totalBytesRead = 0;
466466
while (totalBytesRead < bytesToRead)
467467
{
468-
int bytesRead = await stream.ReadAsync(buffer, totalBytesRead, bytesToRead - totalBytesRead);
468+
int bytesRead = await stream.ReadAsync(buffer.AsMemory(totalBytesRead, bytesToRead - totalBytesRead), CancellationToken.None);
469469
if (bytesRead == 0)
470470
{
471471
return totalBytesRead;

0 commit comments

Comments
 (0)