Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/libraries/Common/src/System/CodeDom/CodeTypeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<string, string> SplitConnectionString(string connectionString, Dictionary<string, string>? synonyms, bool firstKey)
Expand Down
25 changes: 25 additions & 0 deletions src/libraries/Common/src/System/NetStandardShims.String.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);REGISTRY_ASSEMBLY</DefineConstants>
<NoWarn>$(NoWarn);CA2249</NoWarn>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("()");
}
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/System.CodeDom/src/System.CodeDom.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@
<Compile Include="$(CommonPath)System\CSharpHelpers.cs" />
<Compile Include="StringExtensions.cs" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))">
<Compile Include="$(CommonPath)System\NetStandardShims.String.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<NoWarn>$(NoWarn);CA2249</NoWarn>
<IncludeInternalObsoleteAttribute>true</IncludeInternalObsoleteAttribute>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
Expand Down Expand Up @@ -275,6 +274,10 @@
<Compile Include="System\Diagnostics\TraceUtils.cs" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))">
<Compile Include="$(CommonPath)System\NetStandardShims.String.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Diagnostics.EventLog\src\System.Diagnostics.EventLog.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<Compile Include="System\Diagnostics\TraceSourceConfigurationTests.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<Compile Include="System\Drawing\Configuration\SystemDrawingSectionTests.cs" />
</ItemGroup>
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))">
<Compile Include="$(CommonPath)System\NetStandardShims.String.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Configuration.ConfigurationManager.csproj" />
<!-- Apple mobile trimming descriptor for Mono runtime -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('\\');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> -> <'val"ue'>
builder.Append('\'');
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum)-unix;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks Condition="'$(NetCoreAppPrevious)' != ''">$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)-unix;$(NetCoreAppPrevious)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA2249;CA1838</NoWarn>
<NoWarn>$(NoWarn);CA1838</NoWarn>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
<PackageDescription>Provides a collection of classes used to access an ODBC data source in the managed space
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
// <value> -> <value>
builder.Append(keyValue);
}
else if ((-1 != keyValue.IndexOf('\"')) && (-1 == keyValue.IndexOf('\'')))
else if (keyValue.Contains('\"') && keyValue.Contains('\''))
{
// <val"ue> -> <'val"ue'>
builder.Append('\'');
Expand Down Expand Up @@ -760,7 +760,7 @@ private static bool IsValueValidInternal(string? keyvalue)
{
if (null != keyvalue)
{
return (-1 == keyvalue.IndexOf('\u0000'));
return !keyvalue.Contains('\u0000');
}
return true;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks Condition="'$(NetCoreAppPrevious)' != ''">$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Suppress CA2249: Consider using String.Contains instead of String.IndexOf to avoid ifdefs. -->
<NoWarn>$(NoWarn);CA2249</NoWarn>
<!-- Suppress SYSLIB0004: 'RuntimeHelpers.PrepareConstrainedRegions()' is obsolete to avoid ifdefs. -->
<NoWarn>$(NoWarn);SYSLIB0004</NoWarn>
<!-- Suppress CS3016: Arrays as attribute arguments is not CLS-compliant to work around https://github.com/dotnet/roslyn/issues/68526 in generated code -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('\\');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TargetFrameworks Condition="'$(NetCoreAppPrevious)' != ''">$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
<NoWarn>$(NoWarn);CA2249</NoWarn>
<NoWarn>$(NoWarn);IDE0059;IDE0060;CA1822;CA1859</NoWarn>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@
<Compile Include="System\ThrowHelper.cs" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))">
<Compile Include="$(CommonPath)System\NetStandardShims.String.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks Condition="'$(NetCoreAppPrevious)' != ''">$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA2249;CA1865</NoWarn>
<NoWarn>$(NoWarn);CA1865</NoWarn>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
<PackageDescription>Provides the System.ServiceProcess.ServiceController class, which allows you to connect to a Windows service, manipulate it, or get information about it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('\\');
}

/// <summary>
Expand Down