Exemplo n.º 1
0
 public ResultListFilter(PageCriteria paging, SortCriteria sorting)
 {
     Guard.Begin().IsNotNull(paging, nameof(paging)).IsNotNull(sorting, nameof(sorting)).Check();
     Paging  = paging;
     Sorting = sorting;
 }
Exemplo n.º 2
0
 public static IQueryable <T> PagedAndSorted <T>(this IQueryable <T> query, PageCriteria paging, SortCriteria sort, out int total)
 {
     return(query.OrderBy(sort).Paged(paging, out total));
 }
Exemplo n.º 3
0
 public static IQueryable <T> PagedAndSorted <T>(this IQueryable <T> query, PageCriteria paging, SortCriteria sort)
 {
     //simply sort and page
     return(query.OrderBy(sort).Paged(paging));
 }
Exemplo n.º 4
0
        public static IOrderedEnumerable <T> OrderBy <T>(this IEnumerable <T> source, SortCriteria sort)
        {
            if (sort == null)
            {
                return(source.OrderBy(x => x));
            }

            // Reference - http://stackoverflow.com/a/233505
            string[]            props = sort.SortBy.Split('.');
            Type                type  = typeof(T);
            ParameterExpression arg   = Expression.Parameter(type, "p");
            Expression          expr  = arg;

            foreach (string prop in props)
            {
                // use reflection (not ComponentModel) to mirror LINQ
                PropertyInfo pi = type.GetProperty(prop);
                if (pi == null)
                {
                    throw new InvalidOperationException($"Property not found on OrderBy attempt. IEnumerable Item Type: {typeof(T).FullName} | Property Type: {type.FullName} | Property Name: '{prop}' | Full Property Reference: '{sort.SortBy}'.");
                }

                expr = Expression.Property(expr, pi);
                type = pi.PropertyType;
            }

            Type             delegateType = typeof(Func <,>).MakeGenericType(typeof(T), type);
            LambdaExpression lambda       = Expression.Lambda(delegateType, expr, arg);

            object result = typeof(Enumerable).GetMethods().Single(
                method => method.Name == sort.QuerySortOperation &&
                method.IsGenericMethodDefinition &&
                method.GetGenericArguments().Length == 2 &&
                method.GetParameters().Length == 2)
                            .MakeGenericMethod(typeof(T), type)
                            .Invoke(null, new object[] { source, lambda });

            return((IOrderedEnumerable <T>)result);
        }