コード例 #1
0
        public IComparer <T> CreateCompoundComparer(IComparer <T> comparer)
        {
            CompoundComparer <T> compoundComparer = new CompoundComparer <T>();

            compoundComparer.AppendComparison(Comparer);
            compoundComparer.AppendComparison(comparer);
            return(KeyedNullPlacementComparer <T, TKey> .GetComparer(compoundComparer.Normalize(), _keySelector, NullFilter.NullsFirst));
        }
コード例 #2
0
        /// <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>
        /// <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>
        public static IComparer <T> ThenBy <T, TKey>(this IComparer <T> baseComparer, Func <T, TKey> keySelector)
        {
            if (baseComparer == null)
            {
                throw new ArgumentNullException("baseComparer");
            }
            KeyComparer <T> comparer = KeyComparer <T> .OrderBy(keySelector);

            IComparer <T> compoundComparer = CompoundComparer <T> .GetComparer(baseComparer, comparer);

            return(compoundComparer);
        }
コード例 #3
0
        /// <summary>
        /// Composes a comparer that performs subsequent ordering using the comparer.
        /// </summary>
        /// <typeparam name="T">The type being compared.</typeparam>
        /// <param name="baseComparer">The comparer to extend.</param>
        /// <param name="comparer">The comparer 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 comparer is null.</exception>
        public static IComparer <T> ThenBy <T>(this IComparer <T> baseComparer, IComparer <T> comparer)
        {
            if (baseComparer == null)
            {
                throw new ArgumentNullException("baseComparer");
            }
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }
            IComparer <T> compoundComparer = CompoundComparer <T> .GetComparer(baseComparer, comparer);

            return(compoundComparer);
        }
コード例 #4
0
        public void AppendComparison(IComparer <T> comparer)
        {
            if (comparer is NullComparer <T> )
            {
                return;
            }
            CompoundComparer <T> other = comparer as CompoundComparer <T>;

            if (other != null)
            {
                _comparers.AddRange(other._comparers);
                return;
            }
            _comparers.Add(comparer);
        }
コード例 #5
0
        public static IComparer <T> GetComparer(IComparer <T> baseComparer, IComparer <T> nextComparer)
        {
            // make sure null comparer stays highest precedence
            IPrecedenceEnforcer <T> nullComparer = baseComparer as IPrecedenceEnforcer <T>;

            if (nullComparer != null)
            {
                return(nullComparer.CreateCompoundComparer(nextComparer));
            }
            CompoundComparer <T> comparer = new CompoundComparer <T>();

            comparer.AppendComparison(baseComparer);
            comparer.AppendComparison(nextComparer);
            return(comparer.Normalize());
        }
コード例 #6
0
        /// <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);
        }