diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs index 36150e18e1..97785dab99 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs @@ -1808,7 +1808,7 @@ $result } else { - int dotIndex = computerName.IndexOf(".", StringComparison.OrdinalIgnoreCase); + int dotIndex = computerName.IndexOf('.'); if (dotIndex == -1) { localUserName = computerName + "\\" + psLocalCredential.UserName; diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs index aa07697cd9..c2798b03f5 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs @@ -227,7 +227,7 @@ $result { string canonicalName = (string)item.ExtendedProperty("System.ApplicationName"); canonicalName = !string.IsNullOrEmpty(canonicalName) - ? canonicalName.Substring(0, canonicalName.IndexOf("\0", StringComparison.OrdinalIgnoreCase)) + ? canonicalName.Substring(0, canonicalName.IndexOf('\0')) : null; if (canonicalName != null && canonicalName.Equals(RegionCanonicalName, StringComparison.OrdinalIgnoreCase)) @@ -452,7 +452,7 @@ $result string path = item.Path; string canonicalName = (string)item.ExtendedProperty("System.ApplicationName"); canonicalName = canonicalName != null - ? canonicalName.Substring(0, canonicalName.IndexOf("\0", StringComparison.OrdinalIgnoreCase)) + ? canonicalName.Substring(0, canonicalName.IndexOf('\0')) : null; if (canonicalName == null) @@ -640,7 +640,7 @@ $result string description = (string)item.ExtendedProperty("InfoTip"); string canonicalName = (string)item.ExtendedProperty("System.ApplicationName"); canonicalName = canonicalName != null - ? canonicalName.Substring(0, canonicalName.IndexOf("\0", StringComparison.OrdinalIgnoreCase)) + ? canonicalName.Substring(0, canonicalName.IndexOf('\0')) : null; int[] categories = (int[])item.ExtendedProperty("System.ControlPanel.Category"); string[] cateStrings = new string[categories.Length]; diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs index 4a4f559bb1..46e9ba14a2 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs @@ -300,7 +300,7 @@ namespace Microsoft.PowerShell.Commands continue; case qualifierSet: - int separatorIndex = pathsToParse[index].IndexOf(":", StringComparison.CurrentCulture); + int separatorIndex = pathsToParse[index].IndexOf(':'); if (separatorIndex < 0) { @@ -449,7 +449,7 @@ namespace Microsoft.PowerShell.Commands if (SessionState.Path.IsProviderQualified(path)) { - int index = path.IndexOf("::", StringComparison.CurrentCulture); + int index = path.IndexOf("::", StringComparison.Ordinal); if (index != -1) { diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 3e862a9782..2119e51325 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -6600,7 +6600,7 @@ namespace System.Management.Automation } string tooltip = memberInfo.ToString(); - if (tooltip.IndexOf("),", StringComparison.OrdinalIgnoreCase) != -1) + if (tooltip.IndexOf("),", StringComparison.Ordinal) != -1) { var overloads = tooltip.Split(new[] { ")," }, StringSplitOptions.RemoveEmptyEntries); var newTooltip = new StringBuilder(); diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 1df4ffe1c4..75974632bf 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -1505,7 +1505,7 @@ namespace System.Management.Automation private static object NewConverterInstance(string assemblyQualifiedTypeName) { - int typeSeparator = assemblyQualifiedTypeName.IndexOf(",", StringComparison.Ordinal); + int typeSeparator = assemblyQualifiedTypeName.IndexOf(','); if (typeSeparator == -1) { typeConversion.WriteLine("Type name \"{0}\" should be assembly qualified.", assemblyQualifiedTypeName); diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index 855f0ddccd..82c48e5d31 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -4680,7 +4680,7 @@ namespace Microsoft.PowerShell.Commands filePath.StartsWith(@"../", StringComparison.Ordinal) || filePath.StartsWith(@"~/", StringComparison.Ordinal) || filePath.StartsWith(@"~\", StringComparison.Ordinal) || - filePath.IndexOf(":", StringComparison.Ordinal) >= 0); + filePath.Contains(':')); } /// diff --git a/src/System.Management.Automation/engine/ParameterSetInfo.cs b/src/System.Management.Automation/engine/ParameterSetInfo.cs index 7f0d69e881..240a242fcd 100644 --- a/src/System.Management.Automation/engine/ParameterSetInfo.cs +++ b/src/System.Management.Automation/engine/ParameterSetInfo.cs @@ -292,7 +292,7 @@ namespace System.Management.Automation } // If the type is really an array, but the typename didn't include [], then add it. - if (type.IsArray && (parameterTypeString.IndexOf("[]", StringComparison.OrdinalIgnoreCase) == -1)) + if (type.IsArray && (parameterTypeString.IndexOf("[]", StringComparison.Ordinal) == -1)) { var t = type; while (t.IsArray) diff --git a/src/System.Management.Automation/engine/parser/ast.cs b/src/System.Management.Automation/engine/parser/ast.cs index 0ba4a21cd7..434b5a6b5e 100644 --- a/src/System.Management.Automation/engine/parser/ast.cs +++ b/src/System.Management.Automation/engine/parser/ast.cs @@ -8349,7 +8349,7 @@ namespace System.Management.Automation.Language { if (generic == null || !generic.ContainsGenericParameters) { - if (TypeName.FullName.IndexOf("`", StringComparison.OrdinalIgnoreCase) == -1) + if (!TypeName.FullName.Contains('`')) { var newTypeName = new TypeName(Extent, string.Format(CultureInfo.InvariantCulture, "{0}`{1}", TypeName.FullName, GenericArguments.Count)); @@ -8376,7 +8376,7 @@ namespace System.Management.Automation.Language Type generic = TypeName.GetReflectionAttributeType(); if (generic == null || !generic.ContainsGenericParameters) { - if (TypeName.FullName.IndexOf("`", StringComparison.OrdinalIgnoreCase) == -1) + if (!TypeName.FullName.Contains('`')) { var newTypeName = new TypeName(Extent, string.Format(CultureInfo.InvariantCulture, "{0}Attribute`{1}", TypeName.FullName, GenericArguments.Count)); diff --git a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs index 709de06e46..76d1ef2a90 100644 --- a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs +++ b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs @@ -5436,7 +5436,7 @@ Disable-PSRemoting -force:$args[0] -queryForSet $args[1] -captionForSet $args[2] if (!string.IsNullOrEmpty(this.Username)) { - if (this.Username.IndexOf("\\", StringComparison.OrdinalIgnoreCase) >= 0) + if (this.Username.Contains('\\')) { validator = null; diff --git a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs index 6be6c527a4..3f19d2487f 100644 --- a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs +++ b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs @@ -1285,8 +1285,8 @@ namespace System.Management.Automation.Runspaces (RemotingErrorIdStrings.RelativeUriForRunspacePathNotSupported)); } - if (uri.OriginalString.LastIndexOf(":", StringComparison.OrdinalIgnoreCase) > - uri.AbsoluteUri.IndexOf("//", StringComparison.OrdinalIgnoreCase)) + if (uri.OriginalString.LastIndexOf(':') > + uri.AbsoluteUri.IndexOf("//", StringComparison.Ordinal)) { UseDefaultWSManPort = false; } @@ -1296,7 +1296,7 @@ namespace System.Management.Automation.Runspaces // http://localhost , http://127.0.0.1 etc. string appname; - if (uri.AbsolutePath.Equals("/", StringComparison.OrdinalIgnoreCase) && + if (uri.AbsolutePath.Equals("/", StringComparison.Ordinal) && string.IsNullOrEmpty(uri.Query) && string.IsNullOrEmpty(uri.Fragment)) { appname = s_defaultAppName; diff --git a/src/System.Management.Automation/help/SaveHelpCommand.cs b/src/System.Management.Automation/help/SaveHelpCommand.cs index 59801e24c0..048f93ecda 100644 --- a/src/System.Management.Automation/help/SaveHelpCommand.cs +++ b/src/System.Management.Automation/help/SaveHelpCommand.cs @@ -192,7 +192,7 @@ namespace Microsoft.PowerShell.Commands { // Deal with wildcards - int index = path.IndexOf("*", StringComparison.OrdinalIgnoreCase); + int index = path.IndexOf('*'); if (index == 0) { diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 5e128db0e4..9705bbda7a 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -5337,13 +5337,13 @@ namespace Microsoft.PowerShell.Commands { string testPath = path.Replace('/', '\\'); if ( - (testPath.IndexOf("\\", StringComparison.OrdinalIgnoreCase) < 0) || - testPath.StartsWith(".\\", StringComparison.OrdinalIgnoreCase) || - testPath.StartsWith("..\\", StringComparison.OrdinalIgnoreCase) || - testPath.EndsWith("\\.", StringComparison.OrdinalIgnoreCase) || - testPath.EndsWith("\\..", StringComparison.OrdinalIgnoreCase) || - (testPath.IndexOf("\\.\\", StringComparison.OrdinalIgnoreCase) > 0) || - (testPath.IndexOf("\\..\\", StringComparison.OrdinalIgnoreCase) > 0)) + !testPath.Contains('\\') || + testPath.StartsWith(".\\", StringComparison.Ordinal) || + testPath.StartsWith("..\\", StringComparison.Ordinal) || + testPath.EndsWith("\\.", StringComparison.Ordinal) || + testPath.EndsWith("\\..", StringComparison.Ordinal) || + testPath.Contains("\\.\\", StringComparison.Ordinal) || + testPath.Contains("\\..\\", StringComparison.Ordinal)) { try { diff --git a/src/System.Management.Automation/namespaces/LocationGlobber.cs b/src/System.Management.Automation/namespaces/LocationGlobber.cs index c8ce50e355..4ed25f69b2 100644 --- a/src/System.Management.Automation/namespaces/LocationGlobber.cs +++ b/src/System.Management.Automation/namespaces/LocationGlobber.cs @@ -1506,7 +1506,7 @@ namespace System.Management.Automation break; } - int index = path.IndexOf(":", StringComparison.Ordinal); + int index = path.IndexOf(':'); if (index == -1) { @@ -1604,7 +1604,7 @@ namespace System.Management.Automation break; } - int index = path.IndexOf(":", StringComparison.Ordinal); + int index = path.IndexOf(':'); if (index == -1) { @@ -1863,7 +1863,7 @@ namespace System.Management.Automation string normalizedRoot = _sessionState.Drive.Current.Root.Replace( StringLiterals.AlternatePathSeparator, StringLiterals.DefaultPathSeparator); - if (normalizedRoot.IndexOf(":", StringComparison.Ordinal) >= 0) + if (normalizedRoot.Contains(':')) { string normalizedPath = path.Replace(StringLiterals.AlternatePathSeparator, StringLiterals.DefaultPathSeparator); if (normalizedPath.StartsWith(normalizedRoot, StringComparison.OrdinalIgnoreCase)) @@ -3160,7 +3160,7 @@ namespace System.Management.Automation // Find the drive separator only if it's before a path separator - int index = path.IndexOf(":", StringComparison.Ordinal); + int index = path.IndexOf(':'); if (index != -1) { int separator = path.IndexOf(StringLiterals.DefaultPathSeparator, 0, index); diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs index 02ef31e551..7aa18ebee6 100644 --- a/src/System.Management.Automation/namespaces/RegistryProvider.cs +++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs @@ -2958,7 +2958,7 @@ namespace Microsoft.PowerShell.Commands private bool HasRelativePathTokens(string path) { return ( - (path.IndexOf("\\", StringComparison.OrdinalIgnoreCase) == 0) || + path.StartsWith('\\') || path.Contains("\\.\\") || path.Contains("\\..\\") || path.EndsWith("\\..", StringComparison.OrdinalIgnoreCase) || @@ -3332,12 +3332,12 @@ namespace Microsoft.PowerShell.Commands path = NormalizePath(path); - int index = path.IndexOf("\\", StringComparison.Ordinal); + int index = path.IndexOf('\\'); if (index == 0) { // The user may precede a path with \ path = path.Substring(1); - index = path.IndexOf("\\", StringComparison.Ordinal); + index = path.IndexOf('\\'); } if (index == -1) @@ -3522,14 +3522,14 @@ namespace Microsoft.PowerShell.Commands do // false loop { - int index = path.IndexOf("\\", StringComparison.Ordinal); + int index = path.IndexOf('\\'); if (index == 0) { // The user may proceed a path with \ path = path.Substring(1); - index = path.IndexOf("\\", StringComparison.Ordinal); + index = path.IndexOf('\\'); } if (index == -1) diff --git a/src/System.Management.Automation/namespaces/TransactedRegistryKey.cs b/src/System.Management.Automation/namespaces/TransactedRegistryKey.cs index 236fa07055..c43d709691 100644 --- a/src/System.Management.Automation/namespaces/TransactedRegistryKey.cs +++ b/src/System.Management.Automation/namespaces/TransactedRegistryKey.cs @@ -2037,7 +2037,7 @@ namespace Microsoft.PowerShell.Commands.Internal throw new ArgumentNullException(RegistryProviderStrings.Arg_Name); } - int nextSlash = name.IndexOf("\\", StringComparison.OrdinalIgnoreCase); + int nextSlash = name.IndexOf('\\'); int current = 0; while (nextSlash != -1) { @@ -2045,7 +2045,7 @@ namespace Microsoft.PowerShell.Commands.Internal throw new ArgumentException(RegistryProviderStrings.Arg_RegKeyStrLenBug); current = nextSlash + 1; - nextSlash = name.IndexOf("\\", current, StringComparison.OrdinalIgnoreCase); + nextSlash = name.IndexOf('\\', current); } if ((name.Length - current) > MaxKeyLength)