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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 16 additions & 5 deletions src/System.Management.Automation/engine/LanguagePrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
/// 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
/// </summary>
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);
}

/// <summary>
/// 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
/// </summary>
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down