Example #1
0
        public DynamicOrderedQueryable OrderBy(IEnumerable <OrderItem> orderItems)
        {
            if (orderItems == null)
            {
                throw new ArgumentNullException(nameof(orderItems), "Order items cannot be null");
            }
            DynamicOrderedQueryable res = null;

            foreach (var item in orderItems)
            {
                var l =
                    item.ParseExpressionAs == ParseExpressionAs.Property ?
                    Expressions.MemberExpressionBuilder.GetPropertySelector(Source.ElementType, item.Expression) :
                    item.ParseExpressionAs == ParseExpressionAs.NestedProperty ?
                    Expressions.MemberExpressionBuilder.GetDeepPropertySelector(Source.ElementType, item.Expression)
                        :
                    Expressions.MemberExpressionBuilder.GetExpressionSelector(Source.ElementType, item.Expression);

                if (res == null)
                {
                    res = (item.IsDescending ? OrderByDescending(l) : OrderBy(l));
                }
                else
                {
                    res = (item.IsDescending ? res.ThenByDescending(l) : res.ThenBy(l));
                }
            }
            return(res ?? new DynamicOrderedQueryable(Source));
        }
Example #2
0
        public DynamicOrderedQueryable ThenBy(IEnumerable <OrderItem> orderItems)
        {
            if (orderItems == null || !orderItems.Any())
            {
                throw new ArgumentNullException(nameof(orderItems), "Order items cannot be null or empty");
            }

            DynamicOrderedQueryable res = null;

            foreach (var item in orderItems)
            {
                var l = Expressions.MemberExpressionBuilder.GetPropertySelector(Source.ElementType, item.Expression);

                if (res != null)
                {
                    res = (item.IsDescending ? res.ThenByDescending(l) : res.ThenBy(l));
                }
                else
                {
                    res = (item.IsDescending ? OrderByDescending(l) : OrderBy(l));
                }
            }
            return(res);
        }