Ejemplo n.º 1
0
        public IQueryable Sort()
        {
            IQueryable query   = queryable;
            bool       isFirst = true;

            foreach (var descriptor in this.sortDescriptors)
            {
                Type memberType        = typeof(object);
                var  descriptorBuilder = ExpressionBuilderFactory.MemberAccess(queryable, memberType, descriptor.Member);
                var  expression        = descriptorBuilder.CreateLambdaExpression();

                string methodName = "";
                if (isFirst)
                {
                    methodName = descriptor.SortDirection == ListSortDirection.Ascending ?
                                 "OrderBy" : "OrderByDescending";
                    isFirst = false;
                }
                else
                {
                    methodName = descriptor.SortDirection == ListSortDirection.Ascending ?
                                 "ThenBy" : "ThenByDescending";
                }

                query = query.Provider.CreateQuery(
                    Expression.Call(
                        typeof(Queryable),
                        methodName,
                        new[] { query.ElementType, expression.Body.Type },
                        query.Expression,
                        Expression.Quote(expression)));
            }
            return(query);
        }
Ejemplo n.º 2
0
        protected virtual Expression CreateMemberExpression()
        {
            var memberType = this.FilterDescriptor.MemberType;

            var memberAccessBuilder =
                ExpressionBuilderFactory.MemberAccess(this.ParameterExpression.Type, memberType, this.FilterDescriptor.Member);

            memberAccessBuilder.Options.CopyFrom(this.Options);

            memberAccessBuilder.ParameterExpression = this.ParameterExpression;

            Expression memberAccessExpression = memberAccessBuilder.CreateMemberAccessExpression();

            if (memberType != null && memberAccessExpression.Type.GetNonNullableType() != memberType.GetNonNullableType())
            {
                memberAccessExpression = Expression.Convert(memberAccessExpression, memberType);
            }

            return(memberAccessExpression);
        }
Ejemplo n.º 3
0
        public static LambdaExpression Lambda <T>(string memberName, bool checkForNull)
        {
            MemberAccessExpressionBuilderBase expressionBuilder = ExpressionBuilderFactory.MemberAccess(typeof(T), memberName, checkForNull);

            return(expressionBuilder.CreateLambdaExpression());
        }