Ejemplo n.º 1
0
        /// <summary>
        /// Creates a key comparer.
        /// </summary>
        /// <typeparam name="T">The type of object being compared.</typeparam>
        /// <typeparam name="TKey">The type of key objects being compared.</typeparam>
        /// <param name="this">The comparer builder.</param>
        /// <param name="selector">The key selector. May not be <c>null</c>.</param>
        /// <param name="keyComparer">The key comparer. Defaults to <c>null</c>. If this is <c>null</c>, the default comparer is used.</param>
        /// <param name="specialNullHandling">A value indicating whether <c>null</c> values are passed to <paramref name="selector"/>. If <c>false</c>, then <c>null</c> values are considered less than any non-<c>null</c> values and are not passed to <paramref name="selector"/>. This value is ignored if <typeparamref name="T"/> is a non-nullable type.</param>
        /// <param name="descending">A value indicating whether the sorting is done in descending order. If <c>false</c> (the default), then the sort is in ascending order.</param>
        /// <returns>A key comparer.</returns>
        public static IFullComparer <T> OrderBy <T, TKey>(this ComparerBuilderFor <T> @this, Func <T, TKey> selector, IComparer <TKey> keyComparer = null, bool specialNullHandling = false, bool descending = false)
        {
            var selectComparer = new SelectComparer <T, TKey>(selector, keyComparer, specialNullHandling);

            return(descending ? selectComparer.Reverse() : selectComparer);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a comparer that uses a key comparer if the source comparer determines the objects are equal.
        /// </summary>
        /// <typeparam name="T">The type of objects being compared.</typeparam>
        /// <typeparam name="TKey">The type of key objects being compared.</typeparam>
        /// <param name="source">The source comparer. If this is <c>null</c>, the default comparer is used.</param>
        /// <param name="selector">The key selector. May not be <c>null</c>.</param>
        /// <param name="keyComparer">The key comparer. Defaults to <c>null</c>. If this is <c>null</c>, the default comparer is used.</param>
        /// <param name="specialNullHandling">A value indicating whether <c>null</c> values are passed to <paramref name="selector"/>. If <c>false</c>, then <c>null</c> values are considered less than any non-<c>null</c> values and are not passed to <paramref name="selector"/>. This value is ignored if <typeparamref name="T"/> is a non-nullable type.</param>
        /// <param name="descending">A value indicating whether the sorting is done in descending order. If <c>false</c> (the default), then the sort is in ascending order.</param>
        /// <returns>A comparer that uses a key comparer if the source comparer determines the objects are equal.</returns>
        public static IFullComparer <T> ThenBy <T, TKey>(this IComparer <T> source, Func <T, TKey> selector, IComparer <TKey> keyComparer = null, bool specialNullHandling = false, bool descending = false)
        {
            var selectComparer = new SelectComparer <T, TKey>(selector, keyComparer, specialNullHandling);

            return(source.ThenBy(selectComparer, descending));
        }