Пример #1
0
        public SortCriteria(string sortBy, SortDirectionOption direction)
        {
            Guard.Begin().IsNotNull(sortBy, nameof(sortBy)).Check();

            SortBy    = sortBy;
            Direction = direction;
        }
Пример #2
0
        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.");
            }
        }
Пример #3
0
        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.");
            }
        }
Пример #4
0
 public static IOrderedEnumerable <T> OrderBy <T>(this IEnumerable <T> source, string orderBy, SortDirectionOption direction)
 {
     return(source.OrderBy(new SortCriteria(orderBy, direction)));
 }