diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ObjectCommandComparer.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ObjectCommandComparer.cs
index fd69a2011fb..ea2632391ce 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ObjectCommandComparer.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ObjectCommandComparer.cs
@@ -222,7 +222,11 @@ public int Compare(object first, object second)
string firstString = PSObject.AsPSObject(first).ToString();
string secondString = PSObject.AsPSObject(second).ToString();
- return _cultureInfo.CompareInfo.Compare(firstString, secondString, _caseSensitive ? CompareOptions.None : CompareOptions.IgnoreCase) * (_ascendingOrder ? 1 : -1);
+ return string.Compare(
+ firstString,
+ secondString,
+ _cultureInfo,
+ _caseSensitive ? CompareOptions.None : CompareOptions.IgnoreCase) * (_ascendingOrder ? 1 : -1);
}
private CultureInfo _cultureInfo = null;
diff --git a/src/System.Management.Automation/engine/Attributes.cs b/src/System.Management.Automation/engine/Attributes.cs
index 16445703030..352d72fd5d9 100644
--- a/src/System.Management.Automation/engine/Attributes.cs
+++ b/src/System.Management.Automation/engine/Attributes.cs
@@ -1663,10 +1663,10 @@ protected override void ValidateElement(object element)
string objString = element.ToString();
foreach (string setString in ValidValues)
{
- if (CultureInfo.InvariantCulture.CompareInfo.Compare(
+ if (string.Compare(
setString,
objString,
- IgnoreCase ? CompareOptions.IgnoreCase : CompareOptions.None) == 0)
+ IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0)
{
return;
}
diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs
index 5929a5637e9..0cc3b2177b5 100644
--- a/src/System.Management.Automation/engine/LanguagePrimitives.cs
+++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs
@@ -661,8 +661,11 @@ public static bool Equals(object first, object second, bool ignoreCase, IFormatP
if (firstString != null)
{
secondString = second as string ?? (string)LanguagePrimitives.ConvertTo(second, typeof(string), culture);
- return (culture.CompareInfo.Compare(firstString, secondString,
- ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None) == 0);
+ return string.Compare(
+ firstString,
+ secondString,
+ culture,
+ ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None) == 0;
}
if (first.Equals(second)) return true;
@@ -820,8 +823,11 @@ public static int Compare(object first, object second, bool ignoreCase, IFormatP
}
}
- return culture.CompareInfo.Compare(firstString, secondString,
- ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
+ return string.Compare(
+ firstString,
+ secondString,
+ culture,
+ ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
}
Type firstType = first.GetType();
@@ -944,7 +950,12 @@ public static bool TryCompare(object first, object second, bool ignoreCase, IFor
}
}
- result = culture.CompareInfo.Compare(firstString, secondString, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
+ result = string.Compare(
+ firstString,
+ secondString,
+ culture,
+ ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
+
return true;
}
diff --git a/src/System.Management.Automation/engine/runtime/Operations/StringOps.cs b/src/System.Management.Automation/engine/runtime/Operations/StringOps.cs
index 0c4658cc14d..91c6d5b545b 100644
--- a/src/System.Management.Automation/engine/runtime/Operations/StringOps.cs
+++ b/src/System.Management.Automation/engine/runtime/Operations/StringOps.cs
@@ -82,30 +82,20 @@ internal static string FormatOperator(string formatString, object formatArgs)
}
}
- // The following methods are used for the compatibility purpose between regular PowerShell and PowerShell on CSS
-
///
- /// StringComparison.InvariantCulture is not in CoreCLR, so we need to use
- /// CultureInfo.InvariantCulture.CompareInfo.Compare(string, string, CompareOptions)
- /// to substitute
- /// string.Compare(string, string, StringComparison)
+ /// This method is used for the compatibility purpose between regular PowerShell and PowerShell on CSS
///
internal static int Compare(string strA, string strB, CultureInfo culture, CompareOptions option)
{
- Diagnostics.Assert(culture != null, "Caller makes sure that 'culture' is not null.");
- return culture.CompareInfo.Compare(strA, strB, option);
+ return string.Compare(strA, strB, culture, option);
}
///
- /// StringComparison.InvariantCulture is not in CoreCLR, so we need to use
- /// CultureInfo.InvariantCulture.CompareInfo.Compare(string, string, CompareOptions) == 0
- /// to substitute
- /// string.Equals(string, string, StringComparison)
+ /// This method is used for the compatibility purpose between regular PowerShell and PowerShell on CSS
///
internal static bool Equals(string strA, string strB, CultureInfo culture, CompareOptions option)
{
- Diagnostics.Assert(culture != null, "Caller makes sure that 'culture' is not null.");
- return culture.CompareInfo.Compare(strA, strB, option) == 0;
+ return string.Compare(strA, strB, culture, option) == 0;
}
}
}
diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs
index be4b95dc935..a2e746b8363 100644
--- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs
+++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs
@@ -6486,7 +6486,7 @@ public void ClearProperty(
// Only the attributes property can be cleared
if (propertiesToClear.Count > 1 ||
- Host.CurrentCulture.CompareInfo.Compare("Attributes", propertiesToClear[0], CompareOptions.IgnoreCase) != 0)
+ string.Compare("Attributes", propertiesToClear[0], Host.CurrentCulture, CompareOptions.IgnoreCase) != 0)
{
throw PSTraceSource.NewArgumentException(nameof(propertiesToClear), FileSystemProviderStrings.CannotClearProperty);
}