public SortCriteria(string sortBy, SortDirectionOption direction) { Guard.Begin().IsNotNull(sortBy, nameof(sortBy)).Check(); SortBy = sortBy; Direction = direction; }
public static IOrderedQueryable <TSource> OrderBy <TSource, TKey>(this IQueryable <TSource> source, Expression <Func <TSource, TKey> > keySelector, SortDirectionOption direction) { switch (direction) { case SortDirectionOption.Ascending: return(source.OrderBy(keySelector)); case SortDirectionOption.Descending: return(source.OrderByDescending(keySelector)); default: throw new InvalidOperationException("OrderBy SortDirection not valid."); } }
public static IOrderedEnumerable <TSource> ThenBy <TSource, TKey>(this IOrderedEnumerable <TSource> source, Func <TSource, TKey> keySelector, SortDirectionOption direction) { switch (direction) { case SortDirectionOption.Ascending: return(source.ThenBy(keySelector)); case SortDirectionOption.Descending: return(source.ThenByDescending(keySelector)); default: throw new InvalidOperationException("ThenBy SortDirection not valid."); } }
public static IOrderedEnumerable <T> OrderBy <T>(this IEnumerable <T> source, string orderBy, SortDirectionOption direction) { return(source.OrderBy(new SortCriteria(orderBy, direction))); }