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
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ private object Compare(object objValue, object statMinOrMaxValue, bool isMin)
{
object currentValue = objValue;
object statValue = statMinOrMaxValue;
int factor = isMin ? 1 : -1;

double temp;
currentValue = ((objValue != null) && LanguagePrimitives.TryConvertTo<double>(objValue, out temp)) ? temp : currentValue;
Expand All @@ -631,13 +630,15 @@ private object Compare(object objValue, object statMinOrMaxValue, bool isMin)
statValue = PSObject.AsPSObject(statValue).ToString();
}

if ((statValue == null) ||
((LanguagePrimitives.Compare(statValue, currentValue, false, CultureInfo.CurrentCulture) * factor) > 0))
if (statValue == null)
{
return objValue;
}

return statMinOrMaxValue;
int comparisonResult = LanguagePrimitives.Compare(statValue, currentValue, ignoreCase: false, CultureInfo.CurrentCulture);
return (isMin ? comparisonResult : -comparisonResult) > 0
? objValue
: statMinOrMaxValue;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ public int Compare(object first, object second)
second = secondMsh.BaseObject;
}

if (LanguagePrimitives.TryCompare(first, second, !_caseSensitive, _cultureInfo, out int result))
if (!LanguagePrimitives.TryCompare(first, second, !_caseSensitive, _cultureInfo, out int result))
{
return result * (_ascendingOrder ? 1 : -1);
}
// Note that this will occur if the objects do not support
// IComparable. We fall back to comparing as strings.

// Note that this will occur if the objects do not support
// IComparable. We fall back to comparing as strings.
// being here means the first object doesn't support ICompare
string firstString = PSObject.AsPSObject(first).ToString();
string secondString = PSObject.AsPSObject(second).ToString();

// being here means the first object doesn't support ICompare
string firstString = PSObject.AsPSObject(first).ToString();
string secondString = PSObject.AsPSObject(second).ToString();
result = _cultureInfo.CompareInfo.Compare(firstString, secondString, _caseSensitive ? CompareOptions.None : CompareOptions.IgnoreCase);
}

return _cultureInfo.CompareInfo.Compare(firstString, secondString, _caseSensitive ? CompareOptions.None : CompareOptions.IgnoreCase) * (_ascendingOrder ? 1 : -1);
return _ascendingOrder ? result : -result;
}

private readonly CultureInfo _cultureInfo = null;
Expand Down