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 da3b254f99eb25..14f2676a83bacf 100644 --- a/src/libraries/Common/src/System/Data/Common/DbConnectionOptions.Common.cs +++ b/src/libraries/Common/src/System/Data/Common/DbConnectionOptions.Common.cs @@ -403,12 +403,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; } @@ -419,14 +418,13 @@ private static bool IsKeyNameValid([NotNullWhen(true)] string? keyname) { #if DEBUG bool compValue = s_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/NetStandardShims.String.cs b/src/libraries/Common/src/System/NetStandardShims.String.cs new file mode 100644 index 00000000000000..8556e88b6dbb5a --- /dev/null +++ b/src/libraries/Common/src/System/NetStandardShims.String.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System +{ + internal static partial class NetStandardShims + { + extension(string @this) + { + public bool Contains(char value) + { +#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf' + return @this.IndexOf(value) >= 0; +#pragma warning restore CA2249 + } + + public bool Contains(string value, StringComparison comparisonType) + { +#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf' + return @this.IndexOf(value, comparisonType) >= 0; +#pragma warning restore CA2249 + } + } + } +} 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.CodeDom/src/System.CodeDom.csproj b/src/libraries/System.CodeDom/src/System.CodeDom.csproj index 3badaf158c75b3..c429afa4042c78 100644 --- a/src/libraries/System.CodeDom/src/System.CodeDom.csproj +++ b/src/libraries/System.CodeDom/src/System.CodeDom.csproj @@ -138,4 +138,8 @@ + + + + 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 9e1859f7e80ef9..17bbe88e2e3e23 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 @@ -275,6 +274,10 @@ + + + + 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 ef0f34670191a5..528eff10dc29a8 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs @@ -3082,7 +3082,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 @@ -3092,7 +3092,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) @@ -3205,7 +3205,7 @@ internal static string NormalizeConfigSource(string configSource, IConfigErrorIn if (string.IsNullOrEmpty(configSource) || Path.IsPathRooted(configSource)) throw new ConfigurationErrorsException(SR.Config_source_invalid_format, errorInfo); - if (configSource.IndexOf('\\') != -1 || configSource.IndexOf('/') != -1) // string.Contains(char) is .NetCore2.1+ specific + if (configSource.Contains('\\') || configSource.Contains('/')) { string newConfigSource = configSource.Replace('\\', '/'); if (!ConfigPathUtility.IsValid(newConfigSource)) diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationLockCollection.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationLockCollection.cs index 65c73fe77c18c8..02e70d80ded5f0 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationLockCollection.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationLockCollection.cs @@ -219,12 +219,7 @@ internal bool DefinedInParent(string name) } string parentListEnclosed = "," + _seedList + ","; - if (name.Equals(_ignoreName) || -#if NET - parentListEnclosed.Contains("," + name + ",", StringComparison.Ordinal)) -#else - parentListEnclosed.IndexOf("," + name + ",", StringComparison.Ordinal) >= 0) -#endif + if (name.Equals(_ignoreName) || parentListEnclosed.Contains("," + name + ",", StringComparison.Ordinal)) return true; return _internalDictionary.Contains(name) && (((ConfigurationValueFlags)_internalDictionary[name] & ConfigurationValueFlags.Inherited) != 0); 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/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..8d87d784b7ffd3 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 @@ -97,6 +97,9 @@ + + + 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 331969fa50a21f..e2820b69f856d0 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 @@ -167,7 +167,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 +450,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..82954d44796f34 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 diff --git a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs index 16e41fb89f9f97..c3c3ddf86fd9ee 100644 --- a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs +++ b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs @@ -237,7 +237,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('\''); @@ -760,7 +760,7 @@ private static bool IsValueValidInternal(string? keyvalue) { if (null != keyvalue) { - return (-1 == keyvalue.IndexOf('\u0000')); + return !keyvalue.Contains('\u0000'); } return true; } @@ -771,9 +771,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 91422a3cde6375..8fc83ee3eed807 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.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.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj b/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj index c155c10874a6f2..49decbefedd5e8 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System.Reflection.MetadataLoadContext.csproj @@ -151,6 +151,10 @@ + + + + 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 638a47e9bae1a6..0d0808404c4e6b 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 @@ -134,11 +134,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.ServiceProcess.ServiceController/src/System.ServiceProcess.ServiceController.csproj b/src/libraries/System.ServiceProcess.ServiceController/src/System.ServiceProcess.ServiceController.csproj index f212430e588bc9..d4c6564b47bb28 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,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) $(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious) true - $(NoWarn);CA2249;CA1865 + $(NoWarn);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..af2c50ab2f6a6e 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs @@ -456,7 +456,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('\\'); } ///