示例#1
0
        private static BinaryExpression GetExpression <T>(ParameterExpression param, GridHelper.Filter filter1, GridHelper.Filter filter2)
        {
            Expression result1 = GetExpression <T>(param, filter1);
            Expression result2 = GetExpression <T>(param, filter2);

            return(Expression.AndAlso(result1, result2));
        }
示例#2
0
        private static Expression GetExpression <T>(ParameterExpression param, GridHelper.Filter filter)
        {
            // The member you want to evaluate (x => x.FirstName)
            MemberExpression member = Expression.Property(param, filter.PropertyName);

            // The value you want to evaluate
            ConstantExpression constant = Expression.Constant(filter.Value);


            // Determine how we want to apply the expression
            switch (filter.Operator)
            {
            case GridHelper.Operator.Equals:
                return(Expression.Equal(member, constant));

            case GridHelper.Operator.Contains:
                return(Expression.Call(member, containsMethod, constant));

            case GridHelper.Operator.GreaterThan:
                return(Expression.GreaterThan(member, constant));

            case GridHelper.Operator.GreaterThanOrEqual:
                return(Expression.GreaterThanOrEqual(member, constant));

            case GridHelper.Operator.LessThan:
                return(Expression.LessThan(member, constant));

            case GridHelper.Operator.LessThanOrEqualTo:
                return(Expression.LessThanOrEqual(member, constant));

            case GridHelper.Operator.StartsWith:
                return(Expression.Call(member, startsWithMethod, constant));

            case GridHelper.Operator.EndsWith:
                return(Expression.Call(member, endsWithMethod, constant));
            }

            return(null);
        }