diff --git a/src/coreclr/tools/Common/TypeSystem/IL/ILDisassembler.cs b/src/coreclr/tools/Common/TypeSystem/IL/ILDisassembler.cs
index 99660b22c510c3..d2f2522b265c57 100644
--- a/src/coreclr/tools/Common/TypeSystem/IL/ILDisassembler.cs
+++ b/src/coreclr/tools/Common/TypeSystem/IL/ILDisassembler.cs
@@ -283,7 +283,7 @@ public string GetNextInstruction()
// Quick and dirty way to get the opcode name is to convert the enum value to string.
// We need some adjustments though.
string opCodeString = opCode.ToString().Replace("_", ".");
- if (opCodeString.EndsWith("."))
+ if (opCodeString.EndsWith('.'))
opCodeString = opCodeString.Substring(0, opCodeString.Length - 1);
decodedInstruction.Append(opCodeString);
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/PInvokeMethodFixupNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/PInvokeMethodFixupNode.cs
index dae41bc1a7701a..9609ebd21717fa 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/PInvokeMethodFixupNode.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/PInvokeMethodFixupNode.cs
@@ -57,7 +57,7 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
// Entry point name
string entryPointName = _pInvokeMethodData.EntryPointName;
- if (factory.Target.IsWindows && entryPointName.StartsWith("#", StringComparison.OrdinalIgnoreCase))
+ if (factory.Target.IsWindows && entryPointName.StartsWith('#'))
{
// Windows-specific ordinal import
// CLR-compatible behavior: Strings that can't be parsed as a signed integer are treated as zero.
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj b/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj
index c47166526d0b65..2a8741d186f2cb 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj
@@ -4,7 +4,7 @@
ILCompiler.Compiler
$(NetCoreAppToolCurrent)
true
- $(NoWarn);CA1866;CA1867
+ $(NoWarn);CA1866
false
x64;x86
AnyCPU
diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj b/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj
index d8c363424d831a..279b463b2c7594 100644
--- a/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj
+++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj
@@ -5,7 +5,6 @@
ILCompiler.TypeSystem
true
$(NetCoreAppToolCurrent)
- $(NoWarn);CA1866
false
x64;x86
AnyCPU
diff --git a/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs b/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs
index 973d4c63573e70..d967b2375aaa23 100644
--- a/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs
+++ b/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs
@@ -324,7 +324,7 @@ internal static bool TryFindHierarchyMount(CGroupVersion cgroupVersion, string m
{
if (cgroupVersion == CGroupVersion.CGroup1)
{
- bool validCGroup1Entry = mount.FileSystemType.SequenceEqual("cgroup") && mount.SuperOptions.IndexOf(subsystem) >= 0;
+ bool validCGroup1Entry = mount.FileSystemType.SequenceEqual("cgroup") && mount.SuperOptions.Contains(subsystem, StringComparison.Ordinal);
if (!validCGroup1Entry)
{
continue;
diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.IsMemberOfGroup.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.IsMemberOfGroup.cs
index 76302e8ddf5b0a..98e24c9e1f6c98 100644
--- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.IsMemberOfGroup.cs
+++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.IsMemberOfGroup.cs
@@ -33,7 +33,7 @@ internal static unsafe bool IsMemberOfGroup(uint gid)
if (rv >= 0)
{
// success
- return groups.Slice(0, rv).IndexOf(gid) >= 0;
+ return groups.Slice(0, rv).Contains(gid);
}
else if (rv == -1 && Interop.Sys.GetLastError() == Interop.Error.EINVAL)
{
diff --git a/src/libraries/Common/src/System/CodeDom/CodeTypeReference.cs b/src/libraries/Common/src/System/CodeDom/CodeTypeReference.cs
index 347b233a0d97f7..4fadcd6b47c2dd 100644
--- a/src/libraries/Common/src/System/CodeDom/CodeTypeReference.cs
+++ b/src/libraries/Common/src/System/CodeDom/CodeTypeReference.cs
@@ -264,11 +264,7 @@ private void Initialize(string? typeName, CodeTypeReferenceOptions options)
}
// Now see if we have some arity. baseType could be null if this is an array type.
-#if NET
- if (_baseType != null && _baseType.Contains('`')) // string.Contains(char) is .NetCore2.1+ specific
-#else
- if (_baseType != null && _baseType.IndexOf('`') != -1) // string.Contains(char) is .NetCore2.1+ specific
-#endif
+ if (_baseType != null && _baseType.Contains('`'))
{
_needsFixup = false;
}
diff --git a/src/libraries/Common/src/System/Data/Common/DbConnectionOptions.Common.cs b/src/libraries/Common/src/System/Data/Common/DbConnectionOptions.Common.cs
index 7852f3f2b7029f..da10c9fe31f694 100644
--- a/src/libraries/Common/src/System/Data/Common/DbConnectionOptions.Common.cs
+++ b/src/libraries/Common/src/System/Data/Common/DbConnectionOptions.Common.cs
@@ -396,12 +396,11 @@ internal static int GetKeyValuePair(string connectionString, int currentPosition
return currentPosition;
}
-#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'. This file is built into libraries that don't have string.Contains(char).
private static bool IsValueValidInternal(string? keyvalue)
{
if (null != keyvalue)
{
- return (-1 == keyvalue.IndexOf('\u0000')); // string.Contains(char) is .NetCore2.1+ specific
+ return !keyvalue.Contains('\u0000');
}
return true;
}
@@ -412,14 +411,12 @@ private static bool IsKeyNameValid([NotNullWhen(true)] string? keyname)
{
#if DEBUG
bool compValue = ConnectionStringValidKeyRegex.IsMatch(keyname);
- Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000'))) == compValue, "IsValueValid mismatch with regex");
+ Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && !keyname.Contains('\u0000')) == compValue, "IsValueValid mismatch with regex");
#endif
- // string.Contains(char) is .NetCore2.1+ specific
- return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000')));
+ return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && !keyname.Contains('\u0000'));
}
return false;
}
-#pragma warning restore CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'
#if DEBUG
private static Dictionary SplitConnectionString(string connectionString, Dictionary? synonyms, bool firstKey)
diff --git a/src/libraries/Common/src/System/Diagnostics/NetFrameworkUtils.cs b/src/libraries/Common/src/System/Diagnostics/NetFrameworkUtils.cs
index e30106f020012a..f116be728409ee 100644
--- a/src/libraries/Common/src/System/Diagnostics/NetFrameworkUtils.cs
+++ b/src/libraries/Common/src/System/Diagnostics/NetFrameworkUtils.cs
@@ -178,7 +178,7 @@ internal static string GetLatestBuildDllDirectory(string machineName)
string majorVersion = majorVersions[i];
// If this looks like a key of the form v{something}.{something}, we should see if it's a usable build.
- if (majorVersion.Length > 1 && majorVersion[0] == 'v' && majorVersion.Contains(".")) // string.Contains(char) is .NetCore2.1+ specific
+ if (majorVersion.Length > 1 && majorVersion[0] == 'v' && majorVersion.Contains('.'))
{
int[] currentVersion = new int[] { -1, -1, -1 };
diff --git a/src/libraries/Common/src/System/MemoryExtensionsPolyfills.cs b/src/libraries/Common/src/System/MemoryExtensionsPolyfills.cs
index 2836bdee375871..026c8a9708c7e9 100644
--- a/src/libraries/Common/src/System/MemoryExtensionsPolyfills.cs
+++ b/src/libraries/Common/src/System/MemoryExtensionsPolyfills.cs
@@ -6,6 +6,9 @@ namespace System
/// Provides downlevel polyfills for span extension methods.
internal static class MemoryExtensionsPolyfills
{
+ public static bool Contains(this ReadOnlySpan span, T value) where T : IEquatable =>
+ span.IndexOf(value) >= 0;
+
public static bool ContainsAnyExcept(this ReadOnlySpan span, char value)
{
for (int i = 0; i < span.Length; i++)
@@ -18,5 +21,8 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, char value)
return false;
}
+
+ public static bool ContainsAny(this ReadOnlySpan span, ReadOnlySpan values) =>
+ span.IndexOfAny(values) >= 0;
}
}
diff --git a/src/libraries/Common/src/System/StringPolyfills.cs b/src/libraries/Common/src/System/StringPolyfills.cs
new file mode 100644
index 00000000000000..da679b268204f4
--- /dev/null
+++ b/src/libraries/Common/src/System/StringPolyfills.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#if !NETSTANDARD2_1
+
+namespace System
+{
+ /// Provides downlevel polyfills for string extension methods.
+ internal static class StringPolyfills
+ {
+ public static bool StartsWith(this string s, char value) =>
+ s.Length > 0 && s[0] == value;
+
+ public static bool EndsWith(this string s, char value) =>
+ s.Length > 0 && s[s.Length - 1] == value;
+
+ public static bool Contains(this string s, char value) =>
+ s.IndexOf(value) >= 0;
+ }
+}
+
+#endif
diff --git a/src/libraries/Directory.Build.targets b/src/libraries/Directory.Build.targets
index 008038b6c9767f..4bcd8251decdab 100644
--- a/src/libraries/Directory.Build.targets
+++ b/src/libraries/Directory.Build.targets
@@ -187,6 +187,7 @@
+
diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs
index 2623233e69243b..68f7699f2aa981 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs
@@ -54,11 +54,11 @@ public override void Load()
{
keyStartIndex = 2;
}
- else if (currentArg.StartsWith("-"))
+ else if (currentArg.StartsWith('-'))
{
keyStartIndex = 1;
}
- else if (currentArg.StartsWith("/"))
+ else if (currentArg.StartsWith('/'))
{
// "/SomeSwitch" is equivalent to "--SomeSwitch" when interpreting switch mappings
// So we do a conversion to simplify later processing
@@ -141,7 +141,7 @@ private static Dictionary GetValidatedSwitchMappingsCopy(IDictio
foreach (KeyValuePair mapping in switchMappings)
{
// Only keys start with "--" or "-" are acceptable
- if (!mapping.Key.StartsWith("-") && !mapping.Key.StartsWith("--"))
+ if (!mapping.Key.StartsWith('-'))
{
throw new ArgumentException(
SR.Format(SR.Error_InvalidSwitchMapping, mapping.Key),
diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj
index 47ce845bbf01e1..ef6b865ad3ac09 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj
@@ -2,12 +2,15 @@
$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
- $(NoWarn);CA1866
true
true
Command line configuration provider implementation for Microsoft.Extensions.Configuration. This package enables you to read configuration parameters from the command line arguments of your application. You can use CommandLineConfigurationExtensions.AddCommandLine extension method on IConfigurationBuilder to add the command line configuration provider to the configuration builder.
+
+
+
+
diff --git a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Internal/FileSystemInfoHelper.cs b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Internal/FileSystemInfoHelper.cs
index 4796d4a8b0a390..b67a7872eab686 100644
--- a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Internal/FileSystemInfoHelper.cs
+++ b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Internal/FileSystemInfoHelper.cs
@@ -15,7 +15,7 @@ public static bool IsExcluded(FileSystemInfo fileSystemInfo, ExclusionFilters fi
{
return false;
}
- else if (fileSystemInfo.Name.StartsWith(".", StringComparison.Ordinal) && (filters & ExclusionFilters.DotPrefixed) != 0)
+ else if (fileSystemInfo.Name.StartsWith('.') && (filters & ExclusionFilters.DotPrefixed) != 0)
{
return true;
}
diff --git a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Microsoft.Extensions.FileProviders.Physical.csproj b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Microsoft.Extensions.FileProviders.Physical.csproj
index 25096c871c79f4..ae7ebacc83bb92 100644
--- a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Microsoft.Extensions.FileProviders.Physical.csproj
+++ b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/Microsoft.Extensions.FileProviders.Physical.csproj
@@ -4,7 +4,6 @@
$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
Microsoft.Extensions.FileProviders
true
- $(NoWarn);CA1865;CA1866
true
true
File provider for physical files for Microsoft.Extensions.FileProviders.
diff --git a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs
index f61900dbe0e307..c296bfabad95f7 100644
--- a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs
+++ b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs
@@ -153,24 +153,10 @@ private IChangeToken GetOrAddChangeToken(string pattern)
LazyInitializer.EnsureInitialized(ref _timer, ref _timerInitialized, ref _timerLock, _timerFactory);
}
- IChangeToken changeToken;
-#if NET
- bool isWildCard = pattern.Contains('*');
-#else
- bool isWildCard = pattern.IndexOf('*') != -1;
-#endif
- if (isWildCard || IsDirectoryPath(pattern))
- {
- changeToken = GetOrAddWildcardChangeToken(pattern);
- }
- else
- {
+ return pattern.Contains('*') || IsDirectoryPath(pattern)
+ ? GetOrAddWildcardChangeToken(pattern)
// get rid of \. in Windows and ./ in UNIX's at the start of path file
- var filePath = RemoveRelativePathSegment(pattern);
- changeToken = GetOrAddFilePathChangeToken(filePath);
- }
-
- return changeToken;
+ : GetOrAddFilePathChangeToken(RemoveRelativePathSegment(pattern));
}
private static string RemoveRelativePathSegment(string pattern) =>
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj b/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
index b18c834c4e8970..7c4a2308073cc5 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
@@ -4,7 +4,6 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)
true
$(DefineConstants);REGISTRY_ASSEMBLY
- $(NoWarn);CA2249
false
diff --git a/src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs b/src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs
index c95e52baf5600a..4db21ab5b66077 100644
--- a/src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs
+++ b/src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs
@@ -192,10 +192,8 @@ private string QuoteSnippetString(string value)
// If the string is short, use C style quoting (e.g "\r\n")
// Also do it if it is too long to fit in one line
// If the string contains '\0', verbatim style won't work.
-#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'
- if (value.Length < 256 || value.Length > 1500 || (value.IndexOf('\0') != -1)) // string.Contains(char) is .NetCore2.1+ specific
+ if (value.Length < 256 || value.Length > 1500 || value.Contains('\0'))
return QuoteSnippetStringCStyle(value);
-#pragma warning restore CA2249
// Otherwise, use 'verbatim' style quoting (e.g. @"foo")
return QuoteSnippetStringVerbatimStyle(value);
diff --git a/src/libraries/System.CodeDom/src/Microsoft/VisualBasic/VBCodeGenerator.cs b/src/libraries/System.CodeDom/src/Microsoft/VisualBasic/VBCodeGenerator.cs
index 321f03cfb55f56..f607ca6142b213 100644
--- a/src/libraries/System.CodeDom/src/Microsoft/VisualBasic/VBCodeGenerator.cs
+++ b/src/libraries/System.CodeDom/src/Microsoft/VisualBasic/VBCodeGenerator.cs
@@ -862,11 +862,7 @@ protected override void GenerateArrayCreateExpression(CodeArrayCreateExpression
string typeName = GetTypeOutput(e.CreateType);
Output.Write(typeName);
-#if NET
if (!typeName.Contains('('))
-#else
- if (typeName.IndexOf('(') == -1)
-#endif
{
Output.Write("()");
}
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System.Configuration.ConfigurationManager.csproj b/src/libraries/System.Configuration.ConfigurationManager/src/System.Configuration.ConfigurationManager.csproj
index 25598aeb5ac91d..7e2a56b0409616 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System.Configuration.ConfigurationManager.csproj
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System.Configuration.ConfigurationManager.csproj
@@ -2,7 +2,6 @@
$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
- $(NoWarn);CA2249
true
false
true
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs
index 37f9e28d360946..34e5d97befe841 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs
@@ -3078,7 +3078,7 @@ internal static string NormalizeLocationSubPath(string subPath, IConfigErrorInfo
throw new ConfigurationErrorsException(SR.Config_location_path_invalid_first_character, errorInfo);
// do not allow problematic starting characters
- if (InvalidFirstSubPathCharacters.IndexOf(subPath[0]) != -1)
+ if (InvalidFirstSubPathCharacters.Contains(subPath[0]))
throw new ConfigurationErrorsException(SR.Config_location_path_invalid_first_character, errorInfo);
// do not allow whitespace at end of subPath, as the OS
@@ -3088,7 +3088,7 @@ internal static string NormalizeLocationSubPath(string subPath, IConfigErrorInfo
throw new ConfigurationErrorsException(SR.Config_location_path_invalid_last_character, errorInfo);
// the file system ignores trailing '.', '\', or '/', so do not allow it in a location subpath specification
- if (InvalidLastSubPathCharacters.IndexOf(subPath[subPath.Length - 1]) != -1)
+ if (InvalidLastSubPathCharacters.Contains(subPath[subPath.Length - 1]))
throw new ConfigurationErrorsException(SR.Config_location_path_invalid_last_character, errorInfo);
// combination of URI reserved characters and OS invalid filename characters, minus / (allowed reserved character)
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs
index 959ba9bd9ed54e..01d6d7db418252 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs
@@ -133,11 +133,7 @@ internal ConfigurationProperty(PropertyInfo info)
if (collectionAttribute != null)
{
-#if NET
if (!collectionAttribute.AddItemName.Contains(','))
-#else
- if (collectionAttribute.AddItemName.IndexOf(',') == -1)
-#endif
{
AddElementName = collectionAttribute.AddItemName;
}
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSectionCollection.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSectionCollection.cs
index 8429365e9a73fc..ac56de8e86b235 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSectionCollection.cs
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSectionCollection.cs
@@ -85,11 +85,7 @@ public ConfigurationSection Get(string name)
throw ExceptionUtil.ParameterNullOrEmpty(nameof(name));
// prevent GetConfig from returning config not in this collection
-#if NET
if (name.Contains('/'))
-#else
- if (name.IndexOf('/') >= 0)
-#endif
return null;
// get the section from the config record
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSectionGroupCollection.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSectionGroupCollection.cs
index 6d91085612b203..69ae532cae4e07 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSectionGroupCollection.cs
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSectionGroupCollection.cs
@@ -89,11 +89,7 @@ public ConfigurationSectionGroup Get(string name)
throw ExceptionUtil.ParameterNullOrEmpty(nameof(name));
// prevent GetConfig from returning config not in this collection
-#if NET
if (name.Contains('/'))
-#else
- if (name.IndexOf('/') >= 0)
-#endif
return null;
// get the section group
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringAttributeCollection.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringAttributeCollection.cs
index 68b28f95daa007..0388f9c7d5faf2 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringAttributeCollection.cs
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringAttributeCollection.cs
@@ -77,7 +77,7 @@ private void ThrowIfReadOnly()
private static void ThrowIfContainsDelimiter(string value)
{
- if (value.Contains(",")) // string.Contains(char) is .NetCore2.1+ specific
+ if (value.Contains(','))
throw new ConfigurationErrorsException(SR.Format(SR.Config_base_value_cannot_contain, ","));
}
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringValidator.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringValidator.cs
index b5c2d60657f642..2db503a6ed9b49 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringValidator.cs
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringValidator.cs
@@ -21,7 +21,7 @@ public StringValidator(int minLength, int maxLength, string invalidCharacters)
{
_minLength = minLength;
_maxLength = maxLength;
- _invalidChars = invalidCharacters;
+ _invalidChars = invalidCharacters ?? string.Empty;
}
public override bool CanValidate(Type type)
@@ -42,14 +42,9 @@ public override void Validate(object value)
throw new ArgumentException(SR.Format(SR.Validator_string_max_length, _maxLength));
// Check if the string contains any invalid characters
- if ((len > 0) && !string.IsNullOrEmpty(_invalidChars))
+ if (data.AsSpan().ContainsAny(_invalidChars))
{
- char[] array = new char[_invalidChars.Length];
-
- _invalidChars.CopyTo(0, array, 0, _invalidChars.Length);
-
- if (data.IndexOfAny(array) != -1)
- throw new ArgumentException(SR.Format(SR.Validator_string_invalid_chars, _invalidChars));
+ throw new ArgumentException(SR.Format(SR.Validator_string_invalid_chars, _invalidChars));
}
}
}
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/TypeUtil.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/TypeUtil.cs
index aaeb7069786755..75e628672cd386 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/TypeUtil.cs
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/TypeUtil.cs
@@ -49,7 +49,7 @@ private static Type GetImplicitType(string typeString)
// Don't bother to look around if we've already got something that
// is clearly not a simple type name.
- if (string.IsNullOrEmpty(typeString) || typeString.IndexOf(',') != -1) // string.Contains(char) is .NetCore2.1+ specific
+ if (string.IsNullOrEmpty(typeString) || typeString.Contains(','))
return null;
// Ignore all exceptions, otherwise callers will get unexpected
diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj b/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj
index df0132b384c1da..a1d273055b6c58 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj
+++ b/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj
@@ -5,6 +5,11 @@
true
$(DefineConstants);LEGACY_GETRESOURCESTRING_USER
+
+
+
+
+
diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionOptions.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionOptions.cs
index e8d47b42e975c0..abc296ab4c4dcd 100644
--- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionOptions.cs
+++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionOptions.cs
@@ -87,8 +87,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
if (useOdbcRules)
{
if ((0 < keyValue.Length) &&
- // string.Contains(char) is .NetCore2.1+ specific
- (('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || string.Equals(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase)) &&
+ (('{' == keyValue[0]) || keyValue.Contains(';') || 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.Common/src/System/Data/XMLSchema.cs b/src/libraries/System.Data.Common/src/System/Data/XMLSchema.cs
index 208667286d3345..7fc92eb3f0faf7 100644
--- a/src/libraries/System.Data.Common/src/System/Data/XMLSchema.cs
+++ b/src/libraries/System.Data.Common/src/System/Data/XMLSchema.cs
@@ -98,12 +98,12 @@ internal static bool GetBooleanAttribute(XmlElement element, string attrName, st
internal static string GenUniqueColumnName(string proposedName, DataTable table)
{
- if (table.Columns.IndexOf(proposedName) >= 0)
+ if (table.Columns.Contains(proposedName))
{
for (int i = 0; i <= table.Columns.Count; i++)
{
string tempName = proposedName + "_" + (i).ToString(CultureInfo.InvariantCulture);
- if (table.Columns.IndexOf(tempName) >= 0)
+ if (table.Columns.Contains(tempName))
{
continue;
}
@@ -2834,7 +2834,7 @@ internal bool IsTable(XmlSchemaElement node)
}
// internal bool IsTopLevelElement (XmlSchemaElement node) {
- // return (elements.IndexOf(node) != -1);
+ // return (elements.Contains(node));
// }
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
[RequiresDynamicCode(DataSet.RequiresDynamicCodeMessage)]
diff --git a/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/AdapterUtil.Odbc.cs b/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/AdapterUtil.Odbc.cs
index 5be37ae4e4d5e1..51b9b1c360ae2f 100644
--- a/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/AdapterUtil.Odbc.cs
+++ b/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/AdapterUtil.Odbc.cs
@@ -637,7 +637,7 @@ internal static void EscapeSpecialCharacters(string unescapedString, StringBuild
foreach (char currentChar in unescapedString)
{
- if (specialCharacters.IndexOf(currentChar) >= 0)
+ if (specialCharacters.Contains(currentChar))
{
escapedString.Append('\\');
}
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 ee5b8d409a9783..63e9dff14a826d 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
@@ -147,9 +147,8 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
{ // else =;
if (useOdbcRules)
{
- if ((0 < keyValue.Length) &&
- // string.Contains(char) is .NetCore2.1+ specific
- (('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || (string.Equals(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase))) &&
+ if (keyValue.Length > 0 &&
+ (keyValue[0] == '{' || keyValue.Contains(';') || string.Equals(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase)) &&
!ConnectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
{
// always quote Driver value (required for ODBC Version 2.65 and earlier)
@@ -166,8 +165,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
// ->
builder.Append(keyValue);
}
- // string.Contains(char) is .NetCore2.1+ specific
- else if ((-1 != keyValue.IndexOf('\"')) && (-1 == keyValue.IndexOf('\'')))
+ else if (keyValue.Contains('\"') && !keyValue.Contains('\''))
{
// -> <'val"ue'>
builder.Append('\'');
@@ -450,7 +448,7 @@ internal static void ValidateKeyValuePair(string keyword, string value)
{
throw ADP.InvalidKeyname(keyword);
}
- if ((null != value) && value.IndexOf('\0') >= 0)
+ if ((null != value) && value.Contains('\0'))
{
throw ADP.InvalidValue(keyword);
}
diff --git a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
index 34e55db4831286..d1797c145ff06d 100644
--- a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
+++ b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
@@ -4,7 +4,7 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum)-unix;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)-unix;$(NetCoreAppPrevious)
true
- $(NoWarn);CA2249;CA1838
+ $(NoWarn);CA1838
false
true
Provides a collection of classes used to access an ODBC data source in the managed space
@@ -28,6 +28,10 @@ System.Data.Odbc.OdbcTransaction
SR.Odbc_PlatformNotSupported
+
+
+
+
diff --git a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs
index d49016a91be60c..4be3b077731f4b 100644
--- a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs
+++ b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs
@@ -230,7 +230,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
// ->
builder.Append(keyValue);
}
- else if ((-1 != keyValue.IndexOf('\"')) && (-1 == keyValue.IndexOf('\'')))
+ else if (keyValue.Contains('\"') && !keyValue.Contains('\''))
{
// -> <'val"ue'>
builder.Append('\'');
@@ -753,7 +753,7 @@ private static bool IsValueValidInternal(string? keyvalue)
{
if (null != keyvalue)
{
- return (-1 == keyvalue.IndexOf('\u0000'));
+ return !keyvalue.Contains('\u0000');
}
return true;
}
@@ -764,9 +764,9 @@ private static bool IsKeyNameValid([NotNullWhen(true)] string? keyname)
{
#if DEBUG
bool compValue = ConnectionStringValidKeyRegex.IsMatch(keyname);
- Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000'))) == compValue, "IsValueValid mismatch with regex");
+ Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && !keyname.Contains('\u0000')) == compValue, "IsValueValid mismatch with regex");
#endif
- return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000')));
+ return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && !keyname.Contains('\u0000'));
}
return false;
}
diff --git a/src/libraries/System.Data.OleDb/src/OleDbConnectionStringBuilder.cs b/src/libraries/System.Data.OleDb/src/OleDbConnectionStringBuilder.cs
index e3827a3ac40302..c72dc731dc4fad 100644
--- a/src/libraries/System.Data.OleDb/src/OleDbConnectionStringBuilder.cs
+++ b/src/libraries/System.Data.OleDb/src/OleDbConnectionStringBuilder.cs
@@ -631,7 +631,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext? context, Type source
}
else
{
- if (svalue.IndexOf(',') != -1)
+ if (svalue.Contains(','))
{
int convertedValue = 0;
string[] values = svalue.Split(OleDbConnectionInternal.s_comma);
diff --git a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
index ceb89694774b4e..34d3573c62e0ad 100644
--- a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
+++ b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
@@ -4,8 +4,6 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)
true
-
- $(NoWarn);CA2249
$(NoWarn);SYSLIB0004
diff --git a/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs b/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs
index d80f619847a707..debcc8054020bd 100644
--- a/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs
+++ b/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs
@@ -1014,7 +1014,7 @@ internal static void EscapeSpecialCharacters(string unescapedString, StringBuild
foreach (char currentChar in unescapedString)
{
- if (specialCharacters.IndexOf(currentChar) >= 0)
+ if (specialCharacters.Contains(currentChar))
{
escapedString.Append('\\');
}
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs
index 86399634e4da73..c27da2b283ed42 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs
@@ -544,7 +544,7 @@ private static ProcessInfo[] GetProcessInfos(PerformanceCounterLib library, int
// at the end. If instanceName ends in ".", ".e", or ".ex" we remove it.
if (instanceName.Length == 15)
{
- if (instanceName.EndsWith("."))
+ if (instanceName[^1] == '.')
{
instanceName = instanceName.Slice(0, 14);
}
diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj b/src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj
index 2d658680497482..d6146b845716fe 100644
--- a/src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj
+++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj
@@ -5,7 +5,6 @@
$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)
true
true
- $(NoWarn);CA2249
$(NoWarn);IDE0059;IDE0060;CA1822;CA1859
false
true
diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Context.cs b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Context.cs
index 534aa79728132a..1ec57a8c017395 100644
--- a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Context.cs
+++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Context.cs
@@ -100,8 +100,7 @@ private bool BindSam(string target, string userName, string password)
// if they just passed user then append the machine name here.
if (null != userName)
{
- int index = userName.IndexOf('\\');
- if (index == -1)
+ if (!userName.Contains('\\'))
{
userName = _serverName + "\\" + userName;
}
diff --git a/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj b/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj
index 4207345194f521..b9f48b752e74bc 100644
--- a/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj
+++ b/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj
@@ -5,7 +5,7 @@
$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)
true
true
- $(NoWarn);IDE0059;IDE0060;CA1822;CA1865
+ $(NoWarn);IDE0059;IDE0060;CA1822
false
true
true
diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs
index ac1263bc439592..8d634bbb03f974 100644
--- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs
+++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs
@@ -1905,10 +1905,10 @@ internal static string SplitServerNameAndPortNumber(string serverName, out strin
}
//extract IPv6 port number if any
- bool isBrace = serverName.StartsWith("[", StringComparison.Ordinal);
+ bool isBrace = serverName.StartsWith('[');
if (isBrace)
{
- if (serverName.EndsWith("]", StringComparison.Ordinal))
+ if (serverName.EndsWith(']'))
{
//[IPv6]
serverName = serverName.Substring(1, serverName.Length - 2); //2 for []
diff --git a/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj b/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj
index 954c6581382fe7..19a595fb7d3d61 100644
--- a/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj
+++ b/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj
@@ -8,6 +8,7 @@
Provides classes that support storage of multiple data objects in a single container.
false
+ true
@@ -50,7 +51,7 @@
-
+
diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs
index f3dbe73349687e..5c4ec9ea96bb33 100644
--- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs
+++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs
@@ -285,7 +285,7 @@ private void ParseTypeAndSubType(ReadOnlySpan typeAndSubType)
int forwardSlashPos = typeAndSubType.IndexOf('/');
if (forwardSlashPos < 0 || // no slashes
- typeAndSubType.Slice(forwardSlashPos + 1).IndexOf('/') >= 0) // more than one slash
+ typeAndSubType.Slice(forwardSlashPos + 1).Contains('/')) // more than one slash
{
throw new ArgumentException(SR.InvalidTypeSubType);
}
diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs
index 8bf3d1e5a0e8b5..692efce1cf81c7 100644
--- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs
+++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs
@@ -285,11 +285,7 @@ private static string EscapeSpecialCharacters(string path)
// This is currently enforced by the order of characters in the s_specialCharacterChars array
foreach (char c in s_specialCharacterChars)
{
-#if NET
if (path.Contains(c))
-#else
- if (path.IndexOf(c) != -1)
-#endif
{
path = path.Replace(c.ToString(), Uri.HexEscape(c));
}
diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs
index 4764eddffaa51b..19ed7644e1cecc 100644
--- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs
+++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs
@@ -456,7 +456,7 @@ private static void ThrowIfFragmentPresent(string partName)
private static ArgumentException? GetExceptionIfFragmentPresent(string partName)
{
- if (partName.Contains("#")) // string.Contains(char) is .NetCore2.1+ specific
+ if (partName.Contains('#'))
return new ArgumentException(SR.PartUriCannotHaveAFragment);
else
return null;
diff --git a/src/libraries/System.Management/src/System.Management.csproj b/src/libraries/System.Management/src/System.Management.csproj
index 729bfc5e2a3f55..bd2b0f83dc8e28 100644
--- a/src/libraries/System.Management/src/System.Management.csproj
+++ b/src/libraries/System.Management/src/System.Management.csproj
@@ -5,7 +5,7 @@
$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)
true
$(NoWarn);0618
- $(NoWarn);IDE0059;IDE0060;CA1822;CA1865
+ $(NoWarn);IDE0059;IDE0060;CA1822
true
false
true
diff --git a/src/libraries/System.Management/src/System/Management/ManagementPath.cs b/src/libraries/System.Management/src/System/Management/ManagementPath.cs
index 4a28f5e67d1187..8bf9d29ec63533 100644
--- a/src/libraries/System.Management/src/System/Management/ManagementPath.cs
+++ b/src/libraries/System.Management/src/System/Management/ManagementPath.cs
@@ -134,8 +134,7 @@ internal static bool IsValidNamespaceSyntax(string nsPath)
if (nsPath.Length != 0)
{
// Any path separators present?
- char[] pathSeparators = { '\\', '/' };
- if (nsPath.IndexOfAny(pathSeparators) == -1)
+ if (nsPath.AsSpan().IndexOfAny('\\', '/') < 0)
{
// No separators. The only valid path is "root".
if (!string.Equals("root", nsPath, StringComparison.OrdinalIgnoreCase))
diff --git a/src/libraries/System.Management/src/System/Management/ManagementQuery.cs b/src/libraries/System.Management/src/System/Management/ManagementQuery.cs
index 5136a56765b443..14b5457d38027b 100644
--- a/src/libraries/System.Management/src/System/Management/ManagementQuery.cs
+++ b/src/libraries/System.Management/src/System/Management/ManagementQuery.cs
@@ -3038,7 +3038,7 @@ protected internal override void ParseQuery(string query)
throw new ArgumentException(SR.InvalidQuery);
q = q.Remove(0, keyword.Length).TrimStart(null);
- if (!q.StartsWith("*", StringComparison.Ordinal))
+ if (!q.StartsWith('*'))
throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, "*"), nameof(query));
q = q.Remove(0, 1).TrimStart(null);
diff --git a/src/libraries/System.Memory/src/System/Buffers/SequenceReader.Search.cs b/src/libraries/System.Memory/src/System/Buffers/SequenceReader.Search.cs
index f76f6e38440358..a4de015a0efdd2 100644
--- a/src/libraries/System.Memory/src/System/Buffers/SequenceReader.Search.cs
+++ b/src/libraries/System.Memory/src/System/Buffers/SequenceReader.Search.cs
@@ -610,7 +610,7 @@ public long AdvancePastAny(scoped ReadOnlySpan values)
{
// Advance past all matches in the current span
int i;
- for (i = CurrentSpanIndex; i < CurrentSpan.Length && values.IndexOf(CurrentSpan[i]) != -1; i++)
+ for (i = CurrentSpanIndex; i < CurrentSpan.Length && values.Contains(CurrentSpan[i]); i++)
{
}
diff --git a/src/libraries/System.Net.ServerSentEvents/src/System/Net/ServerSentEvents/SseParser_1.cs b/src/libraries/System.Net.ServerSentEvents/src/System/Net/ServerSentEvents/SseParser_1.cs
index 2a3fccc0bf191e..90275fab18ad14 100644
--- a/src/libraries/System.Net.ServerSentEvents/src/System/Net/ServerSentEvents/SseParser_1.cs
+++ b/src/libraries/System.Net.ServerSentEvents/src/System/Net/ServerSentEvents/SseParser_1.cs
@@ -411,7 +411,7 @@ private bool ProcessLine(out SseItem sseItem, out int advance)
else if (fieldName.SequenceEqual("id"u8))
{
// Spec: "If the field value does not contain U+0000 NULL, then set the last event ID buffer to the field value. Otherwise, ignore the field."
- if (fieldValue.IndexOf((byte)'\0') < 0)
+ if (!fieldValue.Contains((byte)'\0'))
{
// Note that fieldValue might be empty, in which case LastEventId will naturally be reset to the empty string. This is per spec.
LastEventId = _eventId = Encoding.UTF8.GetString(fieldValue);
diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj b/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj
index 8bee25d5a44049..20b4bcd95aa7dc 100644
--- a/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj
+++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj
@@ -6,7 +6,6 @@
true
false
true
- $(NoWarn);CA1865
Provides read-only reflection on assemblies in an isolated context with support for assemblies that target different processor architectures and runtimes. Using MetadataLoadContext enables you to inspect assemblies without loading them into the main execution context. Assemblies in MetadataLoadContext are treated only as metadata, that is, you can read information about their members, but cannot execute any code contained in them.
true
diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs
index cfcfd4625667d3..4f0ec58549b67f 100644
--- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs
+++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs
@@ -126,11 +126,7 @@ public static bool NeedsEscapingInTypeName(this char c)
public static string UnescapeTypeNameIdentifier(this string identifier)
{
-#if NET
if (identifier.Contains('\\'))
-#else
- if (identifier.IndexOf('\\') != -1)
-#endif
{
StringBuilder sbUnescapedName = new StringBuilder(identifier.Length);
for (int i = 0; i < identifier.Length; i++)
diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/RuntimeTypeInfo.GetMember.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/RuntimeTypeInfo.GetMember.cs
index f3f2e9f699b382..20d75821fcbfd2 100644
--- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/RuntimeTypeInfo.GetMember.cs
+++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/RuntimeTypeInfo.GetMember.cs
@@ -25,7 +25,7 @@ public sealed override MemberInfo[] GetMember(string name, MemberTypes type, Bin
private MemberInfo[] GetMemberImpl(string? optionalNameOrPrefix, MemberTypes type, BindingFlags bindingAttr)
{
- bool prefixSearch = optionalNameOrPrefix != null && optionalNameOrPrefix.EndsWith("*", StringComparison.Ordinal);
+ bool prefixSearch = optionalNameOrPrefix != null && optionalNameOrPrefix.EndsWith('*');
string? optionalName = prefixSearch ? null : optionalNameOrPrefix;
Func? predicate = null;
diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSMarshalAsAttributeInfoParser.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSMarshalAsAttributeInfoParser.cs
index 179cc065f03ed4..dc40c982b47b3c 100644
--- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSMarshalAsAttributeInfoParser.cs
+++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSMarshalAsAttributeInfoParser.cs
@@ -28,7 +28,7 @@ public MarshallingInfo ParseAttribute(AttributeData attributeData, ITypeSymbol t
{
string gt = jsTypeArgs.ConstructUnboundGenericType().ToDisplayString();
string name = gt.Substring(gt.IndexOf("JSType") + "JSType.".Length);
- name = name.Substring(0, name.IndexOf("<"));
+ name = name.Substring(0, name.IndexOf('<'));
Enum.TryParse(name, out jsType);
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs
index 61ed06504c99b1..d2f312fab6a88e 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs
@@ -380,7 +380,7 @@ protected virtual int DecryptKeyWrapPaddedCore(ReadOnlySpan source, Span 7 || destination.Slice(slen).IndexOfAnyExcept((byte)0) >= 0)
+ if (header != 0xA65959A6 || pad > 7 || destination.Slice(slen).ContainsAnyExcept((byte)0))
{
throw new CryptographicException(SR.Cryptography_KeyWrap_DecryptFailed);
}
diff --git a/src/libraries/System.ServiceProcess.ServiceController/src/System.ServiceProcess.ServiceController.csproj b/src/libraries/System.ServiceProcess.ServiceController/src/System.ServiceProcess.ServiceController.csproj
index f212430e588bc9..7cb8ce7c3fd280 100644
--- a/src/libraries/System.ServiceProcess.ServiceController/src/System.ServiceProcess.ServiceController.csproj
+++ b/src/libraries/System.ServiceProcess.ServiceController/src/System.ServiceProcess.ServiceController.csproj
@@ -4,7 +4,6 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)
true
- $(NoWarn);CA2249;CA1865
false
true
Provides the System.ServiceProcess.ServiceController class, which allows you to connect to a Windows service, manipulate it, or get information about it.
diff --git a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs
index d8b98fc2003828..1ff0d081ab84aa 100644
--- a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs
+++ b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs
@@ -340,7 +340,7 @@ public unsafe ServiceController[] ServicesDependedOn
string dependencyNameStr = new string(dependencyChar, 0, length);
dependencyChar = dependencyChar + length + 1;
length = 0;
- if (dependencyNameStr.StartsWith("+", StringComparison.Ordinal))
+ if (dependencyNameStr.StartsWith('+'))
{
// this entry is actually a service load group
Interop.Advapi32.ENUM_SERVICE_STATUS_PROCESS[] loadGroup = GetServicesInGroup(_machineName, dependencyNameStr.Substring(1));
@@ -455,8 +455,7 @@ public ServiceType ServiceType
private static bool CheckMachineName(string value)
{
- // string.Contains(char) is .NetCore2.1+ specific
- return !string.IsNullOrWhiteSpace(value) && value.IndexOf('\\') == -1;
+ return !string.IsNullOrWhiteSpace(value) && !value.Contains('\\');
}
///
diff --git a/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs b/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs
index 7acbf9c03bdf15..58eb0a098d1637 100644
--- a/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs
+++ b/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs
@@ -1834,7 +1834,7 @@ internal static void ValidateRuleId(string id)
{
Helpers.ThrowIfEmptyOrNull(id, nameof(id));
- if (!XmlReader.IsName(id) || (id == "NULL") || (id == "VOID") || (id == "GARBAGE") || (id.IndexOfAny(s_invalidRuleIdChars) != -1))
+ if (!XmlReader.IsName(id) || (id == "NULL") || (id == "VOID") || (id == "GARBAGE") || (id.ContainsAny(s_invalidRuleIdChars)))
{
XmlParser.ThrowSrgsException(SRID.InvalidRuleId, id);
}
diff --git a/src/libraries/System.Speech/src/Result/RecognizedPhrase.cs b/src/libraries/System.Speech/src/Result/RecognizedPhrase.cs
index 64b192cf83afef..7aa39a17561de6 100644
--- a/src/libraries/System.Speech/src/Result/RecognizedPhrase.cs
+++ b/src/libraries/System.Speech/src/Result/RecognizedPhrase.cs
@@ -670,7 +670,7 @@ private static SemanticValue ExtractSemanticValueInformation(int semanticsOffset
{
IntPtr valueStringBuffer = new((long)phraseBuffer + (int)property.pszValueOffset);
propertyValue = Marshal.PtrToStringUni(valueStringBuffer);
- if (!isSapi53Header && isIdName && ((string)propertyValue).Contains("$"))
+ if (!isSapi53Header && isIdName && ((string)propertyValue).Contains('$'))
{
// SAPI 5.1 result that contains script fragments rather than output of executing script.
// Strip this information as script-based grammars aren't supported on 5.1.
diff --git a/src/libraries/System.Speech/src/System.Speech.csproj b/src/libraries/System.Speech/src/System.Speech.csproj
index 61723c53f0b3a5..1b6ef2b837e87a 100644
--- a/src/libraries/System.Speech/src/System.Speech.csproj
+++ b/src/libraries/System.Speech/src/System.Speech.csproj
@@ -37,6 +37,10 @@ System.Speech.Recognition.SpeechRecognizer
true
+
+
+
+
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs
index bf0d5170468773..71a9b65096ad9c 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs
@@ -409,7 +409,7 @@ internal bool TryGetValue(int index, [NotNullWhen(true)] out byte[]? value)
return JsonReaderHelper.TryGetUnescapedBase64Bytes(segment, out value);
}
- Debug.Assert(segment.IndexOf(JsonConstants.BackSlash) == -1);
+ Debug.Assert(!segment.Contains(JsonConstants.BackSlash));
return JsonReaderHelper.TryDecodeBase64(segment, out value);
}
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
index a6e6983e3c870c..f31686429527d5 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
@@ -701,7 +701,7 @@ private bool ConsumeNumberMultiSegment()
Debug.Assert(
((_consumed < _buffer.Length) &&
!_isNotPrimitive &&
- JsonConstants.Delimiters.IndexOf(_buffer[_consumed]) >= 0)
+ JsonConstants.Delimiters.Contains(_buffer[_consumed]))
|| (_isNotPrimitive ^ (_consumed >= (uint)_buffer.Length)));
return true;
@@ -1306,7 +1306,7 @@ private ConsumeNumberResult ConsumeZeroMultiSegment(ref ReadOnlySpan data,
if (i < data.Length)
{
nextByte = data[i];
- if (JsonConstants.Delimiters.IndexOf(nextByte) >= 0)
+ if (JsonConstants.Delimiters.Contains(nextByte))
{
return ConsumeNumberResult.Success;
}
@@ -1335,7 +1335,7 @@ private ConsumeNumberResult ConsumeZeroMultiSegment(ref ReadOnlySpan data,
i = 0;
data = _buffer;
nextByte = data[i];
- if (JsonConstants.Delimiters.IndexOf(nextByte) >= 0)
+ if (JsonConstants.Delimiters.Contains(nextByte))
{
return ConsumeNumberResult.Success;
}
@@ -1422,7 +1422,7 @@ private ConsumeNumberResult ConsumeIntegerDigitsMultiSegment(ref ReadOnlySpan= 0)
+ if (JsonConstants.Delimiters.Contains(nextByte))
{
return ConsumeNumberResult.Success;
}
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs
index b7f2e7edd9fea6..bef69db6770c99 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs
@@ -43,7 +43,7 @@ public ref partial struct Utf8JsonReader
return JsonReaderHelper.GetUnescapedString(span);
}
- Debug.Assert(span.IndexOf(JsonConstants.BackSlash) == -1);
+ Debug.Assert(!span.Contains(JsonConstants.BackSlash));
return JsonReaderHelper.TranscodeHelper(span);
}
@@ -838,7 +838,7 @@ public bool TryGetBytesFromBase64([NotNullWhen(true)] out byte[]? value)
return JsonReaderHelper.TryGetUnescapedBase64Bytes(span, out value);
}
- Debug.Assert(span.IndexOf(JsonConstants.BackSlash) == -1);
+ Debug.Assert(!span.Contains(JsonConstants.BackSlash));
return JsonReaderHelper.TryDecodeBase64(span, out value);
}
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
index eea091212e14d7..db764ccc153875 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
@@ -1229,7 +1229,7 @@ private bool ConsumeNumber()
Debug.Assert(
((_consumed < _buffer.Length) &&
!_isNotPrimitive &&
- JsonConstants.Delimiters.IndexOf(_buffer[_consumed]) >= 0)
+ JsonConstants.Delimiters.Contains(_buffer[_consumed]))
|| (_isNotPrimitive ^ (_consumed >= (uint)_buffer.Length)));
return true;
@@ -1570,7 +1570,7 @@ private ConsumeNumberResult ConsumeZero(ref ReadOnlySpan data, scoped ref
if (i < data.Length)
{
nextByte = data[i];
- if (JsonConstants.Delimiters.IndexOf(nextByte) >= 0)
+ if (JsonConstants.Delimiters.Contains(nextByte))
{
return ConsumeNumberResult.Success;
}
@@ -1626,7 +1626,7 @@ private ConsumeNumberResult ConsumeIntegerDigits(ref ReadOnlySpan data, sc
return ConsumeNumberResult.NeedMoreData;
}
}
- if (JsonConstants.Delimiters.IndexOf(nextByte) >= 0)
+ if (JsonConstants.Delimiters.Contains(nextByte))
{
return ConsumeNumberResult.Success;
}
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
index 5eb74d3751d711..bf89164f191ff4 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
@@ -573,7 +573,7 @@ private static string ResolveAndValidateJsonName(string name, JsonNamingPolicy?
}
if (string.IsNullOrEmpty(name) || char.IsWhiteSpace(name[0]) || char.IsWhiteSpace(name[name.Length - 1]) ||
- (s_isFlagsEnum && name.AsSpan().IndexOf(',') >= 0))
+ (s_isFlagsEnum && name.Contains(',')))
{
// Reject null or empty strings or strings with leading or trailing whitespace.
// In the case of flags additionally reject strings containing commas.
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs
index 0660197eeb1391..88afb5228e4471 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs
@@ -44,7 +44,7 @@ public void WriteCommentValue(ReadOnlySpan value)
{
JsonWriterHelper.ValidateValue(value);
- if (value.IndexOf(s_singleLineCommentDelimiter) != -1)
+ if (value.Contains(s_singleLineCommentDelimiter, StringComparison.Ordinal))
{
ThrowHelper.ThrowArgumentException_InvalidCommentValue();
}
@@ -161,7 +161,7 @@ public void WriteCommentValue(ReadOnlySpan utf8Value)
{
JsonWriterHelper.ValidateValue(utf8Value);
- if (utf8Value.IndexOf(SingleLineCommentDelimiterUtf8) != -1)
+ if (utf8Value.IndexOf(SingleLineCommentDelimiterUtf8) >= 0)
{
ThrowHelper.ThrowArgumentException_InvalidCommentValue();
}
diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexInterpreter.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexInterpreter.cs
index 6abfc4a1509d5d..e477f7c742babc 100644
--- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexInterpreter.cs
+++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexInterpreter.cs
@@ -299,7 +299,7 @@ private bool MatchRef(int index, int length, ReadOnlySpan inputSpan, bool
// and if so, we need to fetch the case equivalences from our casing tables.
Debug.Assert(_culture != null, "If the pattern has backreferences and is IgnoreCase, then _culture must not be null.");
if (!RegexCaseEquivalences.TryFindCaseEquivalencesForCharWithIBehavior(backreferenceChar, _culture, ref _caseBehavior, out ReadOnlySpan equivalences) ||
- equivalences.IndexOf(inputSpan[pos]) < 0)
+ !equivalences.Contains(inputSpan[pos]))
{
// The backreference character doesn't participate in case conversions, or it does but the input character
// doesn't match any of its equivalents. Either way, we fail to match.
diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs
index 15f5bc8778eb20..201fdef999bab0 100644
--- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs
+++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs
@@ -603,7 +603,7 @@ private static ReadOnlySpan TypeNameReservedChars()
private static bool IsTypeNameReservedChar(char c)
{
- return TypeNameReservedChars().IndexOf(c) != -1;
+ return TypeNameReservedChars().Contains(c);
}
private void EscapeName(string name)
diff --git a/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/NuGetUtils.NuGet.cs b/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/NuGetUtils.NuGet.cs
index 9839bb993e1798..6b337eb8052d39 100644
--- a/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/NuGetUtils.NuGet.cs
+++ b/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/NuGetUtils.NuGet.cs
@@ -52,8 +52,8 @@ bool IsAnalyzer()
&& !file.EndsWith(".resources.dll", StringComparison.OrdinalIgnoreCase);
}
- bool CS() => file.IndexOf("/cs/", StringComparison.OrdinalIgnoreCase) >= 0;
- bool VB() => file.IndexOf("/vb/", StringComparison.OrdinalIgnoreCase) >= 0;
+ bool CS() => file.Contains("/cs/", StringComparison.OrdinalIgnoreCase);
+ bool VB() => file.Contains("/vb/", StringComparison.OrdinalIgnoreCase);
bool FileMatchesProjectLanguage()
{
diff --git a/src/tasks/Crossgen2Tasks/Crossgen2Tasks.csproj b/src/tasks/Crossgen2Tasks/Crossgen2Tasks.csproj
index 8f36adf14547bf..d4c8deba80ee54 100644
--- a/src/tasks/Crossgen2Tasks/Crossgen2Tasks.csproj
+++ b/src/tasks/Crossgen2Tasks/Crossgen2Tasks.csproj
@@ -2,7 +2,7 @@
$(BundledNETCoreAppTargetFramework)
- $(NoWarn);CA1050;CA1852;CA1861;CA2249;IDE0059;IDE0060;IDE0074
+ $(NoWarn);CA1050;CA1852;CA1861;IDE0059;IDE0060;IDE0074
annotations
false
diff --git a/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs b/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs
index c5c7523099e721..22045ddd145fdf 100644
--- a/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs
+++ b/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs
@@ -409,7 +409,7 @@ protected override int ExecuteTool(string pathToTool, string responseFileCommand
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
{
- if (!ShowCompilerWarnings && singleLine.IndexOf("warning:", StringComparison.OrdinalIgnoreCase) != -1)
+ if (!ShowCompilerWarnings && singleLine.Contains("warning:", StringComparison.OrdinalIgnoreCase))
{
Log.LogMessage(MessageImportance.Normal, singleLine);
WarningsDetected = true;
diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs
index 33ddce2302b579..b2bf5d13825cce 100644
--- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs
+++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs
@@ -561,7 +561,7 @@ private bool IsTargetingVersionOrLater(Version version)
if (parsedTargetFrameworkVersion == null)
{
string tfv = TargetFrameworkVersion;
- if (tfv.StartsWith("v"))
+ if (tfv.StartsWith('v'))
tfv = tfv.Substring(1);
parsedTargetFrameworkVersion = Version.Parse(tfv);
diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj
index 379d3cffdc8afb..485f155f1157a6 100644
--- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj
+++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj
@@ -2,7 +2,7 @@
$(NetCoreAppToolCurrent)
- $(NoWarn),CA1050,CA1850,CA1845,CA1859,CA1866,CS8632,NU5128
+ $(NoWarn),CA1050,CA1850,CA1845,CA1859,CS8632,NU5128
Microsoft.NET.Sdk.WebAssembly
true
true