Class SortingExtensions
- Namespace
- NuvTools.Data.Sorting
- Assembly
- NuvTools.Data.dll
Extension methods for sorting collections in both ascending and descending order.
public static class SortingExtensions
- Inheritance
-
SortingExtensions
- Inherited Members
Methods
Sort<T, TKey>(IEnumerable<T>, Func<T, TKey>, SortDirection)
Sorts an enumerable collection by the specified property and direction.
public static IOrderedEnumerable<T> Sort<T, TKey>(this IEnumerable<T> list, Func<T, TKey> property, SortDirection direction = SortDirection.ASC)
Parameters
listIEnumerable<T>The source enumerable collection.
propertyFunc<T, TKey>A function that identifies the property to sort by.
directionSortDirectionThe sort direction (ascending or descending). Defaults to ascending.
Returns
- IOrderedEnumerable<T>
An ordered enumerable collection.
Type Parameters
TThe type of items in the enumerable collection.
TKeyThe type of the property to sort by.
Sort<T, TKey>(IQueryable<T>, Expression<Func<T, TKey>>, SortDirection)
Sorts a queryable collection by the specified property and direction.
public static IOrderedQueryable<T> Sort<T, TKey>(this IQueryable<T> list, Expression<Func<T, TKey>> property, SortDirection direction = SortDirection.ASC)
Parameters
listIQueryable<T>The source queryable collection.
propertyExpression<Func<T, TKey>>An expression that identifies the property to sort by.
directionSortDirectionThe sort direction (ascending or descending). Defaults to ascending.
Returns
- IOrderedQueryable<T>
An ordered queryable collection.
Type Parameters
TThe type of items in the queryable collection.
TKeyThe type of the property to sort by.
ThenSort<T, TKey>(IOrderedEnumerable<T>, Func<T, TKey>, SortDirection)
Performs a secondary sort on an already ordered enumerable collection.
public static IOrderedEnumerable<T> ThenSort<T, TKey>(this IOrderedEnumerable<T> list, Func<T, TKey> property, SortDirection direction = SortDirection.ASC)
Parameters
listIOrderedEnumerable<T>The source ordered enumerable collection.
propertyFunc<T, TKey>A function that identifies the property to sort by.
directionSortDirectionThe sort direction (ascending or descending). Defaults to ascending.
Returns
- IOrderedEnumerable<T>
An ordered enumerable collection with the secondary sort applied.
Type Parameters
TThe type of items in the enumerable collection.
TKeyThe type of the property to sort by.
ThenSort<T, TKey>(IOrderedQueryable<T>, Expression<Func<T, TKey>>, SortDirection)
Performs a secondary sort on an already ordered queryable collection.
public static IOrderedQueryable<T> ThenSort<T, TKey>(this IOrderedQueryable<T> list, Expression<Func<T, TKey>> property, SortDirection direction = SortDirection.ASC)
Parameters
listIOrderedQueryable<T>The source ordered queryable collection.
propertyExpression<Func<T, TKey>>An expression that identifies the property to sort by.
directionSortDirectionThe sort direction (ascending or descending). Defaults to ascending.
Returns
- IOrderedQueryable<T>
An ordered queryable collection with the secondary sort applied.
Type Parameters
TThe type of items in the queryable collection.
TKeyThe type of the property to sort by.