A static class containing helper methods to rewrite expressions into FieldPredicateExpression trees where appropriate.
        /// <summary>
        /// Visits a binary expression, returning a rewritten expression if supported.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        protected override Expression VisitBinaryExpression(BinaryExpression expression)
        {
            var left  = expression.Left;
            var right = expression.Right;

            //if (RebelExpressionRewriter.IsConvertibleBinary(expression))
            //    return RebelExpressionRewriter.ConvertToFieldEvaluationExpression(expression);
            if (FieldPredicateExpressionRewriter.IsConvertibleBinary(expression, StructureBinder))
            {
                return(FieldPredicateExpressionRewriter.ConvertToFieldPredicate(expression, StructureBinder));
            }

            //else make a new binary with the results of visiting deeper in the tree
            var visitedLeft  = VisitExpression(left);
            var visitedRight = VisitExpression(right);

            return(Expression.MakeBinary(expression.NodeType, visitedLeft, visitedRight, expression.IsLiftedToNull, expression.Method));
        }
        protected override Expression VisitUnaryExpression(UnaryExpression expression)
        {
            // The only type of Unary that we support is "Not", i.e. reversing the inner expression
            if (expression.NodeType == ExpressionType.Not)
            {
                var output = VisitExpression(expression.Operand);
                if (typeof(FieldPredicateExpression).IsAssignableFrom(output.GetType()))
                {
                    return(FieldPredicateExpressionRewriter.NegateFieldPredicate(output as FieldPredicateExpression));
                }
            }

            if (expression.NodeType == ExpressionType.Convert &&
                (expression.Type == typeof(object) || IsDynamicMemberGetter(expression.Operand)))
            {
                return(expression.Operand);
            }


            return(base.VisitUnaryExpression(expression));
        }
示例#3
0
 private FieldSelectorExpression GetFieldSelector(QueryModel queryModel, Expression predicate)
 {
     return(FieldPredicateExpressionRewriter.GetFieldSelector(predicate, _treeVisitor.StructureBinder));
 }