예제 #1
0
        public static T Max <T>([NotNull] this IComparer <T> comparer, T x, T y)
        {
            comparer.CheckArgumentNull(nameof(comparer));
            int cmp = comparer.Compare(x, y);

            return(cmp >= 0 ? x : y);
        }
예제 #2
0
 public static TSource Min <TSource>(
     [NotNull] this IEnumerable <TSource> source,
     [NotNull] IComparer <TSource> comparer)
 {
     source.CheckArgumentNull(nameof(source));
     comparer.CheckArgumentNull(nameof(comparer));
     return(source.Extreme(comparer, -1));
 }
예제 #3
0
 public static IComparer <T> ThenBy <T, TKey>(
     [NotNull] this IComparer <T> comparer,
     [NotNull] Func <T, TKey> keySelector,
     IComparer <TKey>?keyComparer = null)
 {
     comparer.CheckArgumentNull(nameof(comparer));
     return(comparer.ChainWith(By(keySelector, keyComparer)));
 }
예제 #4
0
        public static IComparer <T> ChainWith <T>(
            [NotNull] this IComparer <T> comparer,
            [NotNull] IComparer <T> nextComparer)
        {
            comparer.CheckArgumentNull(nameof(comparer));
            nextComparer.CheckArgumentNull(nameof(nextComparer));

            var comparers     = GetComparers(comparer);
            var nextComparers = GetComparers(nextComparer);

            return(new ChainedComparer <T>(comparers.Concat(nextComparers).ToArray()));
        }
예제 #5
0
 public static IComparer <T> Reverse <T>([NotNull] this IComparer <T> comparer)
 {
     comparer.CheckArgumentNull(nameof(comparer));
     return(new ReverseComparer <T>(comparer));
 }