Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Implementation]: Add Order and OrderDescending to Enumerable and Queryable #70525

Merged
merged 19 commits into from
Jun 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 6 additions & 64 deletions src/libraries/System.Linq/src/System/Linq/OrderBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,10 @@ public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source, ICompar
OrderBy(source, static element => element, comparer);

public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
if (keySelector is null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}

return new OrderedEnumerable<TSource, TKey>(source, keySelector, null, false, null);
}
=> OrderBy(source, keySelector, null);
eiriktsarpalis marked this conversation as resolved.
Show resolved Hide resolved

public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey>? comparer)
{
if (keySelector is null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}

return new OrderedEnumerable<TSource, TKey>(source, keySelector, comparer, false, null);
}
=> new OrderedEnumerable<TSource, TKey>(source, keySelector, comparer, false, null);

/// <summary>
/// Sorts the elements of a sequence in descending order.
Expand Down Expand Up @@ -108,60 +94,16 @@ public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this
new OrderedEnumerable<TSource, TKey>(source, keySelector, comparer, true, null);

public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
if (source == null)
deeprobin marked this conversation as resolved.
Show resolved Hide resolved
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (keySelector is null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}

return source.CreateOrderedEnumerable(keySelector, null, false);
}
=> source.CreateOrderedEnumerable(keySelector, null, false);

public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey>? comparer)
{
if (source == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (keySelector is null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}

return source.CreateOrderedEnumerable(keySelector, comparer, false);
}
=> source.CreateOrderedEnumerable(keySelector, comparer, false);

public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
if (source == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (keySelector is null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}

return source.CreateOrderedEnumerable(keySelector, null, true);
}
=> source.CreateOrderedEnumerable(keySelector, null, true);

public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey>? comparer)
{
if (source == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (keySelector is null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}

return source.CreateOrderedEnumerable(keySelector, comparer, true);
}
=> source.CreateOrderedEnumerable(keySelector, comparer, true);
}

public interface IOrderedEnumerable<out TElement> : IEnumerable<TElement>
Expand Down