|
|
@@ -2911,17 +2911,36 @@ namespace InABox.Core
|
|
|
Array.Sort(list, (a, b) => comparison(a).CompareTo(comparison(b)));
|
|
|
}
|
|
|
|
|
|
+ public static void SortByDescending<T, TProp>(this List<T> list, Func<T, TProp> comparison)
|
|
|
+ where TProp : IComparable
|
|
|
+ {
|
|
|
+ list.Sort((a, b) => comparison(b).CompareTo(comparison(a)));
|
|
|
+ }
|
|
|
+
|
|
|
public static void SortBy<T, TProp>(this List<T> list, Func<T, TProp> comparison)
|
|
|
where TProp : IComparable
|
|
|
{
|
|
|
list.Sort((a, b) => comparison(a).CompareTo(comparison(b)));
|
|
|
}
|
|
|
|
|
|
+ public static void SortByDescending<T, TProp>(this T[] list, Func<T, TProp> comparison)
|
|
|
+ where TProp : IComparable
|
|
|
+ {
|
|
|
+ Array.Sort(list, (a, b) => comparison(b).CompareTo(comparison(a)));
|
|
|
+ }
|
|
|
+
|
|
|
public static Comparison<T> OrderBy<T, TProp>(Func<T, TProp> comparison)
|
|
|
where TProp : IComparable
|
|
|
{
|
|
|
return (a, b) => comparison(a).CompareTo(comparison(b));
|
|
|
}
|
|
|
+
|
|
|
+ public static Comparison<T> OrderByDescending<T, TProp>(Func<T, TProp> comparison)
|
|
|
+ where TProp : IComparable
|
|
|
+ {
|
|
|
+ return (a, b) => comparison(b).CompareTo(comparison(a));
|
|
|
+ }
|
|
|
+
|
|
|
public static Comparison<T> ThenBy<T>(this Comparison<T> comparison1, Comparison<T> comparison2)
|
|
|
{
|
|
|
return (x, y) =>
|
|
|
@@ -2954,6 +2973,23 @@ namespace InABox.Core
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ public static Comparison<T> ThenByDescending<T, TProp>(this Comparison<T> comparison1, Func<T, TProp> comparison2)
|
|
|
+ where TProp : IComparable
|
|
|
+ {
|
|
|
+ return (x, y) =>
|
|
|
+ {
|
|
|
+ var result = comparison1(x, y);
|
|
|
+ if (result == 0)
|
|
|
+ {
|
|
|
+ return comparison2(y).CompareTo(comparison2(x));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Compare the elements in this list to the other list, returning <see langword="true"/> if they have all the same
|
|
|
/// elements, regardless of order.
|