Exemplo n.º 1
0
        protected override Expression VisitBinary(BinaryExpression node)
        {
            BooleanClause clause;

            if (ClauseMapping.TryGetValue(node.NodeType, out clause))
            {
                var leftVisitor = new SimpleVisitor();
                leftVisitor.Visit(node.Left);
                var rightVisitor = new SimpleVisitor();
                rightVisitor.Visit(node.Right);
                _filter = new CombinedQueryFilter(leftVisitor._filter, rightVisitor._filter, clause);
                return(node);
            }
            BinaryOperation symbol;

            if (OperationMapping.TryGetValue(node.NodeType, out symbol))
            {
                var leftVisitor = new SimpleVisitor();
                leftVisitor.Visit(node.Left);
                var rightVisitor = new SimpleVisitor();
                rightVisitor.Visit(node.Right);
                var x = new SingleQueryFilter();
                x.AddPredicate(leftVisitor._fieldName, symbol, rightVisitor._value);
                _filter = x;
                return(node);
            }
            throw new NotSupportedException($"不支将 Lamda 表达式解析为 {nameof(QueryFilter)},请确保右侧的表达式是一个符合规范的二元表达式。");
        }
Exemplo n.º 2
0
        public static QueryFilter Where <T>(Expression <Func <T, bool> > expression)
        {
            Guard.ArgumentNotNull(expression, nameof(expression));
            var visitor = new SimpleVisitor();

            visitor.Visit(expression);
            return(visitor.Filter);
        }