1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-10 18:11:04 +09:00

Enable recently added Microsoft.CodeAnalysis.NetAnalyzers rules (#53158)

This commit is contained in:
Stephen Toub 2021-05-28 14:46:46 -04:00 committed by GitHub
parent 4387828740
commit 72ff0df463
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 103 additions and 75 deletions

View file

@ -63,6 +63,7 @@
<Rule Id="CA1307" Action="None" /> <!-- Specify StringComparison -->
<Rule Id="CA1308" Action="None" /> <!-- Normalize strings to uppercase -->
<Rule Id="CA1309" Action="None" /> <!-- Use ordinal stringcomparison -->
<Rule Id="CA1310" Action="Info" /> <!-- Specify StringComparison for correctness -->
<Rule Id="CA1401" Action="Warning" /> <!-- P/Invokes should not be visible -->
<Rule Id="CA1416" Action="Warning" /> <!-- Validate platform compatibility -->
<Rule Id="CA1417" Action="Warning" /> <!-- Do not use 'OutAttribute' on string parameters for P/Invokes -->
@ -119,6 +120,12 @@
<Rule Id="CA1838" Action="Warning" /> <!-- Avoid 'StringBuilder' parameters for P/Invokes -->
<Rule Id="CA1839" Action="Warning" /> <!-- Use 'Environment.ProcessPath' -->
<Rule Id="CA1840" Action="Warning" /> <!-- Use 'Environment.CurrentManagedThreadId' -->
<Rule Id="CA1841" Action="Warning" /> <!-- Prefer Dictionary.Contains methods -->
<Rule Id="CA1842" Action="Warning" /> <!-- Do not use 'WhenAll' with a single task -->
<Rule Id="CA1843" Action="Warning" /> <!-- Do not use 'WaitAll' with a single task -->
<Rule Id="CA1844" Action="Warning" /> <!-- Provide memory-based overrides of async methods when subclassing 'Stream' -->
<Rule Id="CA1845" Action="Warning" /> <!-- Use span-based 'string.Concat' -->
<Rule Id="CA1846" Action="Warning" /> <!-- Prefer 'AsSpan' over 'Substring' -->
<Rule Id="CA2000" Action="None" /> <!-- Dispose objects before losing scope -->
<Rule Id="CA2002" Action="None" /> <!-- Do not lock on objects with weak identity -->
<Rule Id="CA2007" Action="Warning" /> <!-- Consider calling ConfigureAwait on the awaited task -->
@ -165,6 +172,8 @@
<Rule Id="CA2247" Action="Warning" /> <!-- Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum. -->
<Rule Id="CA2248" Action="Warning" /> <!-- Provide correct 'enum' argument to 'Enum.HasFlag' -->
<Rule Id="CA2249" Action="Warning" /> <!-- Consider using 'string.Contains' instead of 'string.IndexOf' -->
<Rule Id="CA2250" Action="Warning" /> <!-- Use 'ThrowIfCancellationRequested' -->
<Rule Id="CA2251" Action="Warning" /> <!-- Use 'string.Equals' -->
<Rule Id="CA2300" Action="None" /> <!-- Do not use insecure deserializer BinaryFormatter -->
<Rule Id="CA2301" Action="None" /> <!-- Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder -->
<Rule Id="CA2302" Action="None" /> <!-- Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize -->

View file

@ -63,6 +63,7 @@
<Rule Id="CA1307" Action="None" /> <!-- Specify StringComparison -->
<Rule Id="CA1308" Action="None" /> <!-- Normalize strings to uppercase -->
<Rule Id="CA1309" Action="None" /> <!-- Use ordinal stringcomparison -->
<Rule Id="CA1310" Action="None" /> <!-- Specify StringComparison for correctness -->
<Rule Id="CA1401" Action="None" /> <!-- P/Invokes should not be visible -->
<Rule Id="CA1416" Action="None" /> <!-- Validate platform compatibility -->
<Rule Id="CA1417" Action="None" /> <!-- Do not use 'OutAttribute' on string parameters for P/Invokes -->
@ -118,6 +119,12 @@
<Rule Id="CA1838" Action="None" /> <!-- Avoid 'StringBuilder' parameters for P/Invokes -->
<Rule Id="CA1839" Action="None" /> <!-- Use 'Environment.ProcessPath' -->
<Rule Id="CA1840" Action="None" /> <!-- Use 'Environment.CurrentManagedThreadId' -->
<Rule Id="CA1841" Action="None" /> <!-- Prefer Dictionary.Contains methods -->
<Rule Id="CA1842" Action="None" /> <!-- Do not use 'WhenAll' with a single task -->
<Rule Id="CA1843" Action="None" /> <!-- Do not use 'WaitAll' with a single task -->
<Rule Id="CA1844" Action="None" /> <!-- Provide memory-based overrides of async methods when subclassing 'Stream' -->
<Rule Id="CA1845" Action="None" /> <!-- Use span-based 'string.Concat' -->
<Rule Id="CA1846" Action="None" /> <!-- Prefer 'AsSpan' over 'Substring' -->
<Rule Id="CA2000" Action="None" /> <!-- Dispose objects before losing scope -->
<Rule Id="CA2002" Action="None" /> <!-- Do not lock on objects with weak identity -->
<Rule Id="CA2007" Action="None" /> <!-- Consider calling ConfigureAwait on the awaited task -->
@ -164,6 +171,8 @@
<Rule Id="CA2247" Action="None" /> <!-- Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum. -->
<Rule Id="CA2248" Action="None" /> <!-- Provide correct 'enum' argument to 'Enum.HasFlag' -->
<Rule Id="CA2249" Action="None" /> <!-- Consider using 'string.Contains' instead of 'string.IndexOf' -->
<Rule Id="CA2250" Action="None" /> <!-- Use 'ThrowIfCancellationRequested' -->
<Rule Id="CA2251" Action="None" /> <!-- Use 'string.Equals' -->
<Rule Id="CA2300" Action="None" /> <!-- Do not use insecure deserializer BinaryFormatter -->
<Rule Id="CA2301" Action="None" /> <!-- Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder -->
<Rule Id="CA2302" Action="None" /> <!-- Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize -->

View file

@ -47,7 +47,7 @@
<MicrosoftCodeAnalysisVersion>3.8.0</MicrosoftCodeAnalysisVersion>
</PropertyGroup>
<PropertyGroup>
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-preview5.21262.4</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-preview6.21274.2</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>3.10.0-2.final</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
<MicrosoftCodeAnalysisCSharpVersion>3.10.0-2.final</MicrosoftCodeAnalysisCSharpVersion>
<!-- Arcade dependencies -->

View file

@ -118,8 +118,9 @@ namespace System.Net.Http
//
// We match behavior of WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY and ignore errors.
string destination = uri.AbsoluteUri;
#pragma warning disable CA1845 // file is shared with a build that lacks string.Concat for spans
// Underlying code does not understand WebSockets so we need to convert it to http or https.
string destination = uri.AbsoluteUri;
if (uri.Scheme == UriScheme.Wss)
{
destination = UriScheme.Https + destination.Substring(UriScheme.Wss.Length);
@ -128,6 +129,7 @@ namespace System.Net.Http
{
destination = UriScheme.Http + destination.Substring(UriScheme.Ws.Length);
}
#pragma warning restore CA1845
var repeat = false;
do

View file

@ -1537,8 +1537,7 @@ Namespace Microsoft.VisualBasic.FileIO
' Remove any separators at the end for the same reason in IsRoot.
Path1 = Path1.TrimEnd(IO.Path.DirectorySeparatorChar, IO.Path.AltDirectorySeparatorChar)
Path2 = Path2.TrimEnd(IO.Path.DirectorySeparatorChar, IO.Path.AltDirectorySeparatorChar)
Return String.Compare(IO.Path.GetPathRoot(Path1), IO.Path.GetPathRoot(Path2),
StringComparison.OrdinalIgnoreCase) = 0
Return String.Equals(IO.Path.GetPathRoot(Path1), IO.Path.GetPathRoot(Path2), StringComparison.OrdinalIgnoreCase)
End Function
''' <summary>
@ -1559,8 +1558,7 @@ Namespace Microsoft.VisualBasic.FileIO
End If
Path = Path.TrimEnd(IO.Path.DirectorySeparatorChar, IO.Path.AltDirectorySeparatorChar)
Return String.Compare(Path, IO.Path.GetPathRoot(Path),
StringComparison.OrdinalIgnoreCase) = 0
Return String.Equals(Path, IO.Path.GetPathRoot(Path), StringComparison.OrdinalIgnoreCase)
End Function
''' <summary>

View file

@ -1233,7 +1233,7 @@ Namespace Microsoft.VisualBasic.FileIO
If Token <> "" Then
If m_HasFieldsEnclosedInQuotes And m_TextFieldType = FieldType.Delimited Then
If String.Compare(Token.Trim(), """", StringComparison.Ordinal) = 0 Then
If String.Equals(Token.Trim(), """", StringComparison.Ordinal) Then
Throw GetInvalidOperationException(SR.TextFieldParser_InvalidComment)
End If
End If

View file

@ -1355,7 +1355,7 @@ Namespace Microsoft.VisualBasic
' compare the filename with the input string case insensitive
' exit loop if match occurs and both files are not sequential input
' and not random/binary.
If System.String.Compare(sPath, oFile.GetAbsolutePath(), StringComparison.OrdinalIgnoreCase) = 0 Then
If System.String.Equals(sPath, oFile.GetAbsolutePath(), StringComparison.OrdinalIgnoreCase) Then
' If path is the same, then verify
' that neither file is open for sequential input
' and that both are open for the same mode (either Binary or Random)

View file

@ -515,7 +515,7 @@ Namespace Microsoft.VisualBasic
ServerName = Nothing
Else
'Does the ServerName match the MachineName?
If String.Compare(Environment.MachineName, ServerName, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Environment.MachineName, ServerName, StringComparison.OrdinalIgnoreCase) Then
ServerName = Nothing
End If
End If

View file

@ -1075,7 +1075,7 @@ RedimAndExit:
Select Case Style.Chars(0)
'(F)ixed
Case "f"c, "F"c
If String.Compare(Style, NAMEDFORMAT_FIXED, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_FIXED, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDbl(Expression).ToString("0.00", Nothing)
Return True
End If
@ -1087,13 +1087,13 @@ RedimAndExit:
'(O)n/off
Select Case Style.Chars(0)
Case "y"c, "Y"c
If String.Compare(Style, NAMEDFORMAT_YES_NO, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_YES_NO, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CInt(CBool(Expression)).ToString(CachedYesNoFormatStyle, Nothing)
Return True
End If
Case "o"c, "O"c
If String.Compare(Style, NAMEDFORMAT_ON_OFF, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_ON_OFF, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CInt(CBool(Expression)).ToString(CachedOnOffFormatStyle, Nothing)
Return True
End If
@ -1104,7 +1104,7 @@ RedimAndExit:
'(P)ercent
Select Case Style.Chars(0)
Case "p"c, "P"c
If String.Compare(Style, NAMEDFORMAT_PERCENT, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_PERCENT, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDbl(Expression).ToString("0.00%", Nothing)
Return True
End If
@ -1117,12 +1117,12 @@ RedimAndExit:
Select Case Style.Chars(0)
Case "s"c, "S"c
If String.Compare(Style, NAMEDFORMAT_STANDARD, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_STANDARD, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDbl(Expression).ToString("N2", Nothing)
Return True
End If
Case "c"c, "C"c
If String.Compare(Style, NAMEDFORMAT_CURRENCY, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_CURRENCY, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDbl(Expression).ToString("C", Nothing)
Return True
End If
@ -1135,13 +1135,13 @@ RedimAndExit:
Select Case Style.Chars(5)
Case "t"c, "T"c
If String.Compare(Style, NAMEDFORMAT_LONG_TIME, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_LONG_TIME, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDate(Expression).ToString("T", Nothing)
Return True
End If
Case "d"c, "D"c
If String.Compare(Style, NAMEDFORMAT_LONG_DATE, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_LONG_DATE, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDate(Expression).ToString("D", Nothing)
Return True
End If
@ -1156,25 +1156,25 @@ RedimAndExit:
Select Case Style.Chars(6)
Case "a"c, "A"c
If String.Compare(Style, NAMEDFORMAT_TRUE_FALSE, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_TRUE_FALSE, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CInt(CBool(Expression)).ToString(CachedTrueFalseFormatStyle, Nothing)
Return True
End If
Case "t"c, "T"c
If String.Compare(Style, NAMEDFORMAT_SHORT_TIME, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_SHORT_TIME, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDate(Expression).ToString("t", Nothing)
Return True
End If
Case "d"c, "D"c
If String.Compare(Style, NAMEDFORMAT_SHORT_DATE, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_SHORT_DATE, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDate(Expression).ToString("d", Nothing)
Return True
End If
Case "i"c, "I"c
If String.Compare(Style, NAMEDFORMAT_SCIENTIFIC, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_SCIENTIFIC, StringComparison.OrdinalIgnoreCase) Then
Dim dbl As Double
dbl = CDbl(Expression)
If System.Double.IsNaN(dbl) OrElse System.Double.IsInfinity(dbl) Then
@ -1194,13 +1194,13 @@ RedimAndExit:
Select Case Style.Chars(7)
Case "t"c, "T"c
If String.Compare(Style, NAMEDFORMAT_MEDIUM_TIME, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_MEDIUM_TIME, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDate(Expression).ToString("T", Nothing)
Return True
End If
Case "d"c, "D"c
If String.Compare(Style, NAMEDFORMAT_MEDIUM_DATE, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_MEDIUM_DATE, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDate(Expression).ToString("D", Nothing)
Return True
End If
@ -1209,7 +1209,7 @@ RedimAndExit:
Case 12
Select Case Style.Chars(0)
Case "g"c, "G"c
If String.Compare(Style, NAMEDFORMAT_GENERAL_DATE, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_GENERAL_DATE, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDate(Expression).ToString("G", Nothing)
Return True
End If
@ -1218,7 +1218,7 @@ RedimAndExit:
Case 14
Select Case Style.Chars(0)
Case "g"c, "G"c
If String.Compare(Style, NAMEDFORMAT_GENERAL_NUMBER, StringComparison.OrdinalIgnoreCase) = 0 Then
If String.Equals(Style, NAMEDFORMAT_GENERAL_NUMBER, StringComparison.OrdinalIgnoreCase) Then
ReturnValue = CDbl(Expression).ToString("G", Nothing)
Return True
End If

View file

@ -150,7 +150,7 @@ namespace System.Data.Common
{
if ((0 < keyValue.Length) &&
// string.Contains(char) is .NetCore2.1+ specific
(('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || (0 == string.Compare(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase))) &&
(('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || (string.Equals(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase))) &&
!s_connectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
{
// always quote Driver value (required for ODBC Version 2.65 and earlier)

View file

@ -211,7 +211,7 @@ namespace System.Data.Common
if (useOdbcRules)
{
if ((0 < keyValue.Length) &&
(('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || (0 == string.Compare(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase))) &&
(('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || (string.Equals(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase))) &&
!ConnectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
{
// always quote Driver value (required for ODBC Version 2.65 and earlier)

View file

@ -90,7 +90,7 @@ namespace System.Data.OleDb
internal OleDbConnectionString(string connectionString, bool validate) : base(connectionString)
{
string? prompt = this[KEY.Prompt];
PossiblePrompt = ((!ADP.IsEmpty(prompt) && (0 != string.Compare(prompt, VALUES.NoPrompt, StringComparison.OrdinalIgnoreCase)))
PossiblePrompt = ((!ADP.IsEmpty(prompt) && (!string.Equals(prompt, VALUES.NoPrompt, StringComparison.OrdinalIgnoreCase)))
|| !ADP.IsEmpty(this[KEY.WindowHandle]));
if (!IsEmpty)

View file

@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLSCompliant>false</CLSCompliant>
<NoWarn>$(NoWarn);SA1205</NoWarn>
<NoWarn>$(NoWarn);SA1205;CA1845</NoWarn>
<Nullable>enable</Nullable>
<TargetFrameworks>$(NetCoreAppCurrent);net5.0;netstandard2.0;net461</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>

View file

@ -195,11 +195,11 @@ namespace System.Diagnostics.Eventing.Reader
if (channelRefDisplayName == null && isImported)
{
if (string.Compare(channelName, "Application", StringComparison.OrdinalIgnoreCase) == 0)
if (string.Equals(channelName, "Application", StringComparison.OrdinalIgnoreCase))
channelRefMessageId = 256;
else if (string.Compare(channelName, "System", StringComparison.OrdinalIgnoreCase) == 0)
else if (string.Equals(channelName, "System", StringComparison.OrdinalIgnoreCase))
channelRefMessageId = 258;
else if (string.Compare(channelName, "Security", StringComparison.OrdinalIgnoreCase) == 0)
else if (string.Equals(channelName, "Security", StringComparison.OrdinalIgnoreCase))
channelRefMessageId = 257;
else
channelRefMessageId = -1;

View file

@ -622,8 +622,8 @@ namespace System.Management
this.isLocal = false;
// determine if the server is local, and if so don't create a real stub using unsecap
if ((0 == string.Compare(eventWatcher.Scope.Path.Server, ".", StringComparison.OrdinalIgnoreCase)) ||
(0 == string.Compare(eventWatcher.Scope.Path.Server, System.Environment.MachineName, StringComparison.OrdinalIgnoreCase)))
if ((string.Equals(eventWatcher.Scope.Path.Server, ".", StringComparison.OrdinalIgnoreCase)) ||
(string.Equals(eventWatcher.Scope.Path.Server, System.Environment.MachineName, StringComparison.OrdinalIgnoreCase)))
{
this.isLocal = true;
}

View file

@ -634,7 +634,7 @@ namespace System.Management
string oldValue = Server;
// Only set if changed
if (0 != string.Compare(oldValue, value, StringComparison.OrdinalIgnoreCase))
if (!string.Equals(oldValue, value, StringComparison.OrdinalIgnoreCase))
{
if (null == wmiPath)
wmiPath = (IWbemPath)MTAHelper.CreateInMTA(typeof(WbemDefPath)); //new WbemDefPath ();
@ -888,7 +888,7 @@ namespace System.Management
string oldValue = ClassName;
// Only set if changed
if (0 != string.Compare(oldValue, value, StringComparison.OrdinalIgnoreCase))
if (!string.Equals(oldValue, value, StringComparison.OrdinalIgnoreCase))
{
// isWbemPathShared handled in internal className property accessor.
internalClassName = value;

View file

@ -75,8 +75,8 @@ namespace System.Management
if (null != path)
{
this.path = new ManagementPath(path);
if ((0 == string.Compare(this.path.Server, ".", StringComparison.OrdinalIgnoreCase)) ||
(0 == string.Compare(this.path.Server, System.Environment.MachineName, StringComparison.OrdinalIgnoreCase)))
if ((string.Equals(this.path.Server, ".", StringComparison.OrdinalIgnoreCase)) ||
(string.Equals(this.path.Server, System.Environment.MachineName, StringComparison.OrdinalIgnoreCase)))
{
this.isLocal = true;
}
@ -87,8 +87,8 @@ namespace System.Management
this.scope = (ManagementScope)scope.Clone();
if (null == path) // use scope to see if sink is local
{
if ((0 == string.Compare(this.scope.Path.Server, ".", StringComparison.OrdinalIgnoreCase)) ||
(0 == string.Compare(this.scope.Path.Server, System.Environment.MachineName, StringComparison.OrdinalIgnoreCase)))
if ((string.Equals(this.scope.Path.Server, ".", StringComparison.OrdinalIgnoreCase)) ||
(string.Equals(this.scope.Path.Server, System.Environment.MachineName, StringComparison.OrdinalIgnoreCase)))
{
this.isLocal = true;
}

View file

@ -10,6 +10,8 @@ using System.Threading.Tasks;
using SafeWinHttpHandle = Interop.WinHttp.SafeWinHttpHandle;
#pragma warning disable CA1844 // lack of WriteAsync(ReadOnlyMemory) override in .NET Standard 2.1 build
namespace System.Net.Http
{
internal sealed class WinHttpRequestStream : Stream

View file

@ -10,6 +10,8 @@ using System.Threading.Tasks;
using SafeWinHttpHandle = Interop.WinHttp.SafeWinHttpHandle;
#pragma warning disable CA1844 // lack of ReadAsync(Memory) override in .NET Standard 2.1 build
namespace System.Net.Http
{
internal sealed class WinHttpResponseStream : Stream

View file

@ -454,21 +454,14 @@ namespace System.Net.Http
set => throw new NotSupportedException();
}
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
if (offset < 0)
{
throw new ArgumentOutOfRangeException(nameof(offset));
}
if (count < 0 || buffer.Length - offset < count)
{
throw new ArgumentOutOfRangeException(nameof(count));
}
ValidateBufferArguments(buffer, offset, count);
return ReadAsync(new Memory<byte>(buffer, offset, count), cancellationToken).AsTask();
}
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken)
{
if (_reader == null)
{
// If we've read everything, then _reader and _status will be null
@ -527,13 +520,13 @@ namespace System.Net.Http
int ReadBuffered()
{
int n = _bufferedBytes.Length - _position;
if (n > count)
n = count;
int n = Math.Min(_bufferedBytes.Length - _position, buffer.Length);
if (n <= 0)
{
return 0;
}
Buffer.BlockCopy(_bufferedBytes, _position, buffer, offset, n);
_bufferedBytes.AsSpan(_position, n).CopyTo(buffer.Span);
_position += n;
return n;

View file

@ -365,7 +365,7 @@ namespace System.Net
if (st > 0)
{
_saved.Append(stString.Substring(0, _saved.Length == 0 ? st - 2 : st));
_saved.Append(stString.AsSpan(0, _saved.Length == 0 ? st - 2 : st));
st = 0;
if (_saved.Length > 4196)
ThrowProtocolViolation("Error reading trailer (too long).");

View file

@ -9,6 +9,8 @@ using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
#pragma warning disable CA1844 // Memory-based Read/WriteAsync
namespace System.Net.WebSockets
{
internal sealed class WebSocketHttpListenerDuplexStream : Stream, WebSocketBase.IWebSocketStream

View file

@ -2,13 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
namespace System.Net
{
internal class DelegatedStream : Stream
internal abstract class DelegatedStream : Stream
{
private readonly Stream _stream;
@ -109,8 +108,7 @@ namespace System.Net
if (!CanRead)
throw new NotSupportedException(SR.ReadNotSupported);
int read = _stream.EndRead(asyncResult);
return read;
return _stream.EndRead(asyncResult);
}
public override void EndWrite(IAsyncResult asyncResult)
@ -136,8 +134,7 @@ namespace System.Net
if (!CanRead)
throw new NotSupportedException(SR.ReadNotSupported);
int read = _stream.Read(buffer, offset, count);
return read;
return _stream.Read(buffer, offset, count);
}
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
@ -148,13 +145,20 @@ namespace System.Net
return _stream.ReadAsync(buffer, offset, count, cancellationToken);
}
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
{
if (!CanRead)
throw new NotSupportedException(SR.ReadNotSupported);
return _stream.ReadAsync(buffer, cancellationToken);
}
public override long Seek(long offset, SeekOrigin origin)
{
if (!CanSeek)
throw new NotSupportedException(SR.SeekNotSupported);
long position = _stream.Seek(offset, origin);
return position;
return _stream.Seek(offset, origin);
}
public override void SetLength(long value)
@ -180,5 +184,13 @@ namespace System.Net
return _stream.WriteAsync(buffer, offset, count, cancellationToken);
}
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
{
if (!CanWrite)
throw new NotSupportedException(SR.WriteNotSupported);
return _stream.WriteAsync(buffer, cancellationToken);
}
}
}

View file

@ -270,7 +270,7 @@ namespace System.Xml
{
if (_inclusivePrefixes[i].Length == xmlnsAttribute.prefixLength)
{
if (string.Compare(Encoding.UTF8.GetString(_xmlnsBuffer!, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength), _inclusivePrefixes[i], StringComparison.Ordinal) == 0)
if (string.Equals(Encoding.UTF8.GetString(_xmlnsBuffer!, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength), _inclusivePrefixes[i], StringComparison.Ordinal))
{
return true;
}

View file

@ -792,7 +792,7 @@ namespace System.Xml
throw new ArgumentException(SR.Xml_InvalidPiChars);
}
if (0 == string.Compare(name, "xml", StringComparison.OrdinalIgnoreCase) && _stateTable == s_stateTableDocument)
if (string.Equals(name, "xml", StringComparison.OrdinalIgnoreCase) && _stateTable == s_stateTableDocument)
{
throw new ArgumentException(SR.Xml_DupXmlDecl);
}

View file

@ -1613,8 +1613,7 @@ namespace System.Xml.Schema
// Compare the float and double values. We can't do simple value comparison
// as conversion from float to double introduces imprecissions which cause problems.
// Instead we will convert both back to string and compare the strings.
if (string.Compare(XmlConvert.ToString(flValue), XmlConvert.ToString(dbValue),
StringComparison.OrdinalIgnoreCase) == 0)
if (string.Equals(XmlConvert.ToString(flValue), XmlConvert.ToString(dbValue), StringComparison.OrdinalIgnoreCase))
{
// If we can convert the original string to the exact same value
// and it still fits into float then we treat it as float

View file

@ -94,7 +94,7 @@ namespace System.Speech.Internal.ObjectTokens
public override bool Equals(object obj)
{
ObjectToken token = obj as ObjectToken;
return token != null && string.Compare(Id, token.Id, StringComparison.OrdinalIgnoreCase) == 0;
return token != null && string.Equals(Id, token.Id, StringComparison.OrdinalIgnoreCase);
}
/// <summary>

View file

@ -294,7 +294,7 @@ namespace System.Speech.Internal.Synthesis
for (int iDevice = 0; iDevice < NumDevices(); iDevice++)
{
string device;
if (GetDeviceName(iDevice, out device) == MMSYSERR.NOERROR && string.Compare(device, name, StringComparison.OrdinalIgnoreCase) == 0)
if (GetDeviceName(iDevice, out device) == MMSYSERR.NOERROR && string.Equals(device, name, StringComparison.OrdinalIgnoreCase))
{
return iDevice;
}

View file

@ -105,7 +105,7 @@ namespace Microsoft.WebAssembly.Diagnostics
if (result != null && error != null)
throw new ArgumentException($"Both {nameof(result)} and {nameof(error)} arguments cannot be non-null.");
bool resultHasError = string.Compare((result?["result"] as JObject)?["subtype"]?.Value<string>(), "error") == 0;
bool resultHasError = string.Equals((result?["result"] as JObject)?["subtype"]?.Value<string>(), "error");
if (result != null && resultHasError)
{
this.Value = null;
@ -257,7 +257,7 @@ namespace Microsoft.WebAssembly.Diagnostics
if (stackId?.StartsWith("dotnet:", StringComparison.Ordinal) != true)
return false;
return int.TryParse(stackId.Substring("dotnet:".Length), out id);
return int.TryParse(stackId.AsSpan("dotnet:".Length), out id);
}
public Breakpoint(string stackId, SourceLocation loc, string condition, BreakpointState state)