Table of Contents

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

list IEnumerable<T>

The source enumerable collection.

property Func<T, TKey>

A function that identifies the property to sort by.

direction SortDirection

The sort direction (ascending or descending). Defaults to ascending.

Returns

IOrderedEnumerable<T>

An ordered enumerable collection.

Type Parameters

T

The type of items in the enumerable collection.

TKey

The 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

list IQueryable<T>

The source queryable collection.

property Expression<Func<T, TKey>>

An expression that identifies the property to sort by.

direction SortDirection

The sort direction (ascending or descending). Defaults to ascending.

Returns

IOrderedQueryable<T>

An ordered queryable collection.

Type Parameters

T

The type of items in the queryable collection.

TKey

The 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

list IOrderedEnumerable<T>

The source ordered enumerable collection.

property Func<T, TKey>

A function that identifies the property to sort by.

direction SortDirection

The sort direction (ascending or descending). Defaults to ascending.

Returns

IOrderedEnumerable<T>

An ordered enumerable collection with the secondary sort applied.

Type Parameters

T

The type of items in the enumerable collection.

TKey

The 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

list IOrderedQueryable<T>

The source ordered queryable collection.

property Expression<Func<T, TKey>>

An expression that identifies the property to sort by.

direction SortDirection

The sort direction (ascending or descending). Defaults to ascending.

Returns

IOrderedQueryable<T>

An ordered queryable collection with the secondary sort applied.

Type Parameters

T

The type of items in the queryable collection.

TKey

The type of the property to sort by.