/// <summary> /// Composes a comparer that performs subsequent ordering using the key comparison. /// </summary> /// <typeparam name="T">The type being compared.</typeparam> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="baseComparer">The comparer to extend.</param> /// <param name="keySelector">The key of the type to use for comparison.</param> /// <param name="keyComparison">The comparison delegate to use to compare the keys.</param> /// <returns>A comparer that performs comparisons using both comparison operations.</returns> /// <exception cref="System.ArgumentNullException">The base comparer is null.</exception> /// <exception cref="System.ArgumentNullException">The key selector is null.</exception> /// <exception cref="System.ArgumentNullException">The key comparison delegate is null.</exception> public static IComparer <T> ThenBy <T, TKey>( this IComparer <T> baseComparer, Func <T, TKey> keySelector, Func <TKey, TKey, int> keyComparison) { if (baseComparer is null) { throw new ArgumentNullException(nameof(baseComparer)); } var comparer = KeyComparer <T> .OrderBy(keySelector, keyComparison); var compoundComparer = CompoundComparer <T> .GetComparer(baseComparer, comparer); return(compoundComparer); }
/// <summary> /// Composes a comparer that performs subsequent ordering using the comparison. /// </summary> /// <typeparam name="T">The type being compared.</typeparam> /// <param name="baseComparer">The comparer to extend.</param> /// <param name="comparison">The comparison to use if two items compare as equal using the base comparer.</param> /// <returns>A comparer that performs comparisons using both comparison operations.</returns> /// <exception cref="System.ArgumentNullException">The base comparer is null.</exception> /// <exception cref="System.ArgumentNullException">The comparison delegate is null.</exception> public static IComparer <T> ThenBy <T>(this IComparer <T> baseComparer, Func <T, T, int> comparison) { if (baseComparer is null) { throw new ArgumentNullException(nameof(baseComparer)); } if (comparison is null) { throw new ArgumentNullException(nameof(comparison)); } var wrapper = ComparisonWrapper <T> .GetComparer(comparison); var compoundComparer = CompoundComparer <T> .GetComparer(baseComparer, wrapper); return(compoundComparer); }
/// <summary> /// Composes a comparer that performs subsequent ordering using the comparison. /// </summary> /// <typeparam name="T">The type being compared.</typeparam> /// <param name="baseComparer">The comparer to extend.</param> /// <param name="comparison">The comparison to use if two items compare as equal using the base comparer.</param> /// <returns>A comparer that performs comparisons using both comparison operations.</returns> /// <exception cref="System.ArgumentNullException">The base comparer is null.</exception> /// <exception cref="System.ArgumentNullException">The comparison delegate is null.</exception> public static IComparer <T> ThenBy <T>(this IComparer <T> baseComparer, Func <T, T, int> comparison) { if (baseComparer == null) { throw new ArgumentNullException("baseComparer"); } if (comparison == null) { throw new ArgumentNullException("comparison"); } IComparer <T> wrapper = ComparisonWrapper <T> .GetComparer(comparison); IComparer <T> compoundComparer = CompoundComparer <T> .GetComparer(baseComparer, wrapper); return(compoundComparer); }