diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset
index fe63588a31cd4..4631414599589 100644
--- a/eng/CodeAnalysis.ruleset
+++ b/eng/CodeAnalysis.ruleset
@@ -63,6 +63,7 @@
+
@@ -119,6 +120,12 @@
+
+
+
+
+
+
@@ -165,6 +172,8 @@
+
+
diff --git a/eng/CodeAnalysis.test.ruleset b/eng/CodeAnalysis.test.ruleset
index 142a1e8e86384..1be671aaa3a3f 100644
--- a/eng/CodeAnalysis.test.ruleset
+++ b/eng/CodeAnalysis.test.ruleset
@@ -63,6 +63,7 @@
+
@@ -118,6 +119,12 @@
+
+
+
+
+
+
@@ -164,6 +171,8 @@
+
+
diff --git a/eng/Versions.props b/eng/Versions.props
index 9f33fa85db888..404af554fdb08 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -47,7 +47,7 @@
3.8.0
- 6.0.0-preview5.21262.4
+ 6.0.0-preview6.21274.2
3.10.0-2.final
3.10.0-2.final
diff --git a/src/libraries/Common/src/System/Net/Http/WinInetProxyHelper.cs b/src/libraries/Common/src/System/Net/Http/WinInetProxyHelper.cs
index 1e623f7a7df0f..04ea230cfd4c6 100644
--- a/src/libraries/Common/src/System/Net/Http/WinInetProxyHelper.cs
+++ b/src/libraries/Common/src/System/Net/Http/WinInetProxyHelper.cs
@@ -118,8 +118,9 @@ public bool GetProxyForUrl(
//
// 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 @@ public bool GetProxyForUrl(
{
destination = UriScheme.Http + destination.Substring(UriScheme.Ws.Length);
}
+#pragma warning restore CA1845
var repeat = false;
do
diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileIO/FileSystem.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileIO/FileSystem.vb
index 8205efd585e4d..9f57364a19a97 100644
--- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileIO/FileSystem.vb
+++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileIO/FileSystem.vb
@@ -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
'''
@@ -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
'''
diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileIO/TextFieldParser.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileIO/TextFieldParser.vb
index cd92369dfcd3c..9f9140eb84623 100644
--- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileIO/TextFieldParser.vb
+++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileIO/TextFieldParser.vb
@@ -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
diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb
index a19189d80e21c..265ccae60e5a8 100644
--- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb
+++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb
@@ -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)
diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Interaction.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Interaction.vb
index 1f861f2193cab..ff87277720b4f 100644
--- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Interaction.vb
+++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Interaction.vb
@@ -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
diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Strings.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Strings.vb
index 8baa886059e44..1357ed3395966 100644
--- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Strings.vb
+++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Strings.vb
@@ -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
diff --git a/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/DbConnectionOptions.cs b/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/DbConnectionOptions.cs
index 893a3e2084a4c..d752d1233af8e 100644
--- a/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/DbConnectionOptions.cs
+++ b/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/DbConnectionOptions.cs
@@ -150,7 +150,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
{
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)
diff --git a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs
index 11c5e01bb4b5f..2d47d32c4d9f2 100644
--- a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs
+++ b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs
@@ -211,7 +211,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
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)
diff --git a/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs b/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs
index 7f3946291684b..e31ff207c5709 100644
--- a/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs
+++ b/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs
@@ -90,7 +90,7 @@ private static class VALUES
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)
diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
index 32e49f46ad47b..b6c1170ce6475 100644
--- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
+++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
@@ -1,8 +1,8 @@
-
+
true
false
- $(NoWarn);SA1205
+ $(NoWarn);SA1205;CA1845
enable
$(NetCoreAppCurrent);net5.0;netstandard1.1;netstandard1.3;net45;net46;netstandard2.0
true
diff --git a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/ProviderMetadata.cs b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/ProviderMetadata.cs
index 381d37e780aca..e43b7af67cc23 100644
--- a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/ProviderMetadata.cs
+++ b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/ProviderMetadata.cs
@@ -195,11 +195,11 @@ public IList LogLinks
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;
diff --git a/src/libraries/System.Management/src/System/Management/ManagementEventWatcher.cs b/src/libraries/System.Management/src/System/Management/ManagementEventWatcher.cs
index 3d0a26a575fcd..95e5a894a9549 100644
--- a/src/libraries/System.Management/src/System/Management/ManagementEventWatcher.cs
+++ b/src/libraries/System.Management/src/System/Management/ManagementEventWatcher.cs
@@ -622,8 +622,8 @@ public SinkForEventQuery(ManagementEventWatcher eventWatcher,
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;
}
diff --git a/src/libraries/System.Management/src/System/Management/ManagementPath.cs b/src/libraries/System.Management/src/System/Management/ManagementPath.cs
index fab177277f276..def7a2f356d1a 100644
--- a/src/libraries/System.Management/src/System/Management/ManagementPath.cs
+++ b/src/libraries/System.Management/src/System/Management/ManagementPath.cs
@@ -634,7 +634,7 @@ public string Server
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 @@ public string ClassName
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;
diff --git a/src/libraries/System.Management/src/System/Management/WmiEventSink.cs b/src/libraries/System.Management/src/System/Management/WmiEventSink.cs
index 151b16d665a92..76ebc13838026 100644
--- a/src/libraries/System.Management/src/System/Management/WmiEventSink.cs
+++ b/src/libraries/System.Management/src/System/Management/WmiEventSink.cs
@@ -75,8 +75,8 @@ protected WmiEventSink(ManagementOperationObserver watcher,
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 @@ protected WmiEventSink(ManagementOperationObserver watcher,
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;
}
diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs
index e963aad6ce40f..301e5a6a21fc8 100644
--- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs
+++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs
@@ -10,6 +10,8 @@
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
diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs
index 2922291faa01f..16d0235d55331 100644
--- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs
+++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs
@@ -10,6 +10,8 @@
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
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
index a4298dba53a70..7eb3a3ddc13b9 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
@@ -454,21 +454,14 @@ public override long Position
set => throw new NotSupportedException();
}
- public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
+ public override Task 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(buffer, offset, count), cancellationToken).AsTask();
+ }
+ public override async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken)
+ {
if (_reader == null)
{
// If we've read everything, then _reader and _status will be null
@@ -527,13 +520,13 @@ public override async Task ReadAsync(byte[] buffer, int offset, int count,
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;
diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/ChunkStream.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/ChunkStream.cs
index 0d87301a10e5d..97efc781a7841 100644
--- a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/ChunkStream.cs
+++ b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/ChunkStream.cs
@@ -365,7 +365,7 @@ private State ReadTrailer(byte[] buffer, ref int offset, int size)
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).");
diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketHttpListenerDuplexStream.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketHttpListenerDuplexStream.cs
index a3702c28d23aa..0e1845499519c 100644
--- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketHttpListenerDuplexStream.cs
+++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketHttpListenerDuplexStream.cs
@@ -9,6 +9,8 @@
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
diff --git a/src/libraries/System.Net.Mail/src/System/Net/DelegatedStream.cs b/src/libraries/System.Net.Mail/src/System/Net/DelegatedStream.cs
index e9f4261e339f7..d253ef78f3648 100644
--- a/src/libraries/System.Net.Mail/src/System/Net/DelegatedStream.cs
+++ b/src/libraries/System.Net.Mail/src/System/Net/DelegatedStream.cs
@@ -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 @@ public override int EndRead(IAsyncResult asyncResult)
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 @@ public override int Read(byte[] buffer, int offset, int count)
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 ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
@@ -148,13 +145,20 @@ public override Task ReadAsync(byte[] buffer, int offset, int count, Cancel
return _stream.ReadAsync(buffer, offset, count, cancellationToken);
}
+ public override ValueTask ReadAsync(Memory 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 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
return _stream.WriteAsync(buffer, offset, count, cancellationToken);
}
+
+ public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default)
+ {
+ if (!CanWrite)
+ throw new NotSupportedException(SR.WriteNotSupported);
+
+ return _stream.WriteAsync(buffer, cancellationToken);
+ }
}
}
diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlCanonicalWriter.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlCanonicalWriter.cs
index 24c718eb3bf58..11dc79d1834fd 100644
--- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlCanonicalWriter.cs
+++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlCanonicalWriter.cs
@@ -270,7 +270,7 @@ private bool IsInclusivePrefix(ref XmlnsAttribute xmlnsAttribute)
{
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;
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs
index 95733a0e82740..a594d83bbb326 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs
@@ -792,7 +792,7 @@ public override void WriteProcessingInstruction(string name, string? text)
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);
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/Infer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/Infer.cs
index 58e9c0ddf9354..86fc6cd39535d 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/Infer.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/Infer.cs
@@ -1613,8 +1613,7 @@ internal XmlQualifiedName RefineSimpleType(string s, ref int iTypeFlags)
// 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
diff --git a/src/libraries/System.Speech/src/Internal/ObjectToken/ObjectToken.cs b/src/libraries/System.Speech/src/Internal/ObjectToken/ObjectToken.cs
index 1d38e938bbdd7..461212e622b67 100644
--- a/src/libraries/System.Speech/src/Internal/ObjectToken/ObjectToken.cs
+++ b/src/libraries/System.Speech/src/Internal/ObjectToken/ObjectToken.cs
@@ -94,7 +94,7 @@ protected override void Dispose(bool disposing)
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);
}
///
diff --git a/src/libraries/System.Speech/src/Internal/Synthesis/AudioDeviceOut.cs b/src/libraries/System.Speech/src/Internal/Synthesis/AudioDeviceOut.cs
index 5f1ea529efeb6..9df323e94c7da 100644
--- a/src/libraries/System.Speech/src/Internal/Synthesis/AudioDeviceOut.cs
+++ b/src/libraries/System.Speech/src/Internal/Synthesis/AudioDeviceOut.cs
@@ -294,7 +294,7 @@ internal static int GetDevicedId(string name)
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;
}
diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs
index 7cc78357f9e41..efb2a7b4a2a79 100644
--- a/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs
+++ b/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs
@@ -105,7 +105,7 @@ private Result(JObject result, JObject error)
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(), "error") == 0;
+ bool resultHasError = string.Equals((result?["result"] as JObject)?["subtype"]?.Value(), "error");
if (result != null && resultHasError)
{
this.Value = null;
@@ -257,7 +257,7 @@ public static bool TryParseId(string stackId, out int id)
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)