Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ dotnet_diagnostic.CA2247.severity = warning
dotnet_diagnostic.CA2248.severity = suggestion

# CA2249: Consider using 'string.Contains' instead of 'string.IndexOf'
dotnet_diagnostic.CA2249.severity = suggestion
dotnet_diagnostic.CA2249.severity = warning

# CA2300: Do not use insecure deserializer BinaryFormatter
dotnet_diagnostic.CA2300.severity = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1985,9 +1985,9 @@ private static string EscapeFunctionNameForRemoteHelp(string name)
StringBuilder result = new(name.Length);
foreach (char c in name)
{
if (("\"'`$".IndexOf(c) == (-1)) &&
(!char.IsControl(c)) &&
(!char.IsWhiteSpace(c)))
if (!"\"'`$".Contains(c)
&& !char.IsControl(c)
&& !char.IsWhiteSpace(c))
{
result.Append(c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,9 @@ private static string EscapeModuleNameForHelpComment(string name)
StringBuilder result = new(name.Length);
foreach (char c in name)
{
if (("\"'`$#".IndexOf(c) == (-1)) &&
(!char.IsControl(c)) &&
(!char.IsWhiteSpace(c)))
if (!"\"'`$#".Contains(c)
&& !char.IsControl(c)
&& !char.IsWhiteSpace(c))
{
result.Append(c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ internal static object GetConverter(Type type, TypeTable backupTypeTable)

private static object NewConverterInstance(string assemblyQualifiedTypeName)
{
if (assemblyQualifiedTypeName.IndexOf(',') == -1)
if (!assemblyQualifiedTypeName.Contains(','))
{
typeConversion.WriteLine("Type name \"{0}\" should be assembly qualified.", assemblyQualifiedTypeName);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,10 @@ private static IEnumerable<CimModule> GetCimModules(
ErrorRecord errorRecord = GetErrorRecordForRemoteDiscoveryProvider(exception);
if (!cmdlet.MyInvocation.ExpectingInput)
{
if ((errorRecord.FullyQualifiedErrorId.IndexOf(DiscoveryProviderNotFoundErrorId, StringComparison.OrdinalIgnoreCase) != (-1)) ||
(cancellationToken.IsCancellationRequested || (exception is OperationCanceledException)) ||
(!cimSession.TestConnection()))
if (errorRecord.FullyQualifiedErrorId.Contains(DiscoveryProviderNotFoundErrorId, StringComparison.OrdinalIgnoreCase)
|| cancellationToken.IsCancellationRequested
|| exception is OperationCanceledException
|| !cimSession.TestConnection())
{
cmdlet.ThrowTerminatingError(errorRecord);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1104,10 +1104,9 @@ private static string ResolveShellUri(string shell)
resolvedShellUri = DefaultShellUri;
}

if (resolvedShellUri.IndexOf(
System.Management.Automation.Remoting.Client.WSManNativeApi.ResourceURIPrefix, StringComparison.OrdinalIgnoreCase) == -1)
if (!resolvedShellUri.Contains(WSManNativeApi.ResourceURIPrefix, StringComparison.OrdinalIgnoreCase))
{
resolvedShellUri = System.Management.Automation.Remoting.Client.WSManNativeApi.ResourceURIPrefix + resolvedShellUri;
resolvedShellUri = WSManNativeApi.ResourceURIPrefix + resolvedShellUri;
}

return resolvedShellUri;
Expand Down Expand Up @@ -1414,8 +1413,7 @@ internal bool UseDefaultWSManPort
/// <summary>
/// Default value for shell.
/// </summary>
private const string DefaultShellUri =
System.Management.Automation.Remoting.Client.WSManNativeApi.ResourceURIPrefix + RemotingConstants.DefaultShellName;
private const string DefaultShellUri = WSManNativeApi.ResourceURIPrefix + RemotingConstants.DefaultShellName;

/// <summary>
/// Default credentials - null indicates credentials of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ internal override IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool
{
if (decoratedSearch)
{
if (target.IndexOf(StringLiterals.CommandVerbNounSeparator) >= 0)
if (target.Contains(StringLiterals.CommandVerbNounSeparator))
{
patternList.Add(target + "*");
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/help/MUIFileSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private static string[] GetFiles(string path, string pattern)

foreach (string filePath in files)
{
if (filePath.IndexOf(pattern, StringComparison.OrdinalIgnoreCase) >= 0)
if (filePath.Contains(pattern, StringComparison.OrdinalIgnoreCase))
{
result.Add(filePath);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ internal static AmsiNativeMethods.AMSI_RESULT WinScanContent(string content, str
const string EICAR_STRING = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*";
if (InternalTestHooks.UseDebugAmsiImplementation)
{
if (content.IndexOf(EICAR_STRING, StringComparison.Ordinal) >= 0)
if (content.Contains(EICAR_STRING, StringComparison.Ordinal))
{
return AmsiNativeMethods.AMSI_RESULT.AMSI_RESULT_DETECTED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private static SystemEnforcementMode GetDebugLockdownPolicy(string path)
{
// Assume everything under SYSTEM32 is trusted, with a purposefully sloppy
// check so that we can actually put it in the filename during testing.
if (path.IndexOf("System32", StringComparison.OrdinalIgnoreCase) >= 0)
if (path.Contains("System32", StringComparison.OrdinalIgnoreCase))
{
return SystemEnforcementMode.None;
}
Expand Down