예제 #1
0
        public static OrCondition operator |(Condition condition1, Condition condition2)
        {
            OrCondition or = new OrCondition(condition1, condition2);

            return(or);
        }
예제 #2
0
 protected override Expression VisitBinary(BinaryExpression node)
 {
     parentXExpressionType.Push(node.NodeType);
     if (node.NodeType == ExpressionType.And || node.NodeType == ExpressionType.AndAlso)
     {
         AndCondition and = new AndCondition();
         if (condition == null)
         {
             condition = and;
         }
         if (currentNodes.Count > 0)
         {
             ((ConditionGroup)currentNodes.Peek()).Add(and);
         }
         currentNodes.Push(and);
         Visit(node.Left);
         MakeCallExpression(node.Left);
         Visit(node.Right);
         MakeCallExpression(node.Right);
         currentNodes.Pop();
     }
     else if (node.NodeType == ExpressionType.Or || node.NodeType == ExpressionType.OrElse)
     {
         OrCondition or = new OrCondition();
         if (condition == null)
         {
             condition = or;
         }
         if (currentNodes.Count > 0)
         {
             ((ConditionGroup)currentNodes.Peek()).Add(or);
         }
         currentNodes.Push(or);
         Visit(node.Left);
         Visit(node.Right);
         currentNodes.Pop();
     }
     else if (node.NodeType == ExpressionType.LessThan)
     {
         Visit(node.Left);
         Visit(node.Right);
         var c = CreateCondition(ConditionType.Lessthan);
         if (condition == null)
         {
             condition = c;
         }
         if (currentNodes.Count > 0)
         {
             ((ConditionGroup)currentNodes.Peek()).Add(c);
         }
     }
     else if (node.NodeType == ExpressionType.LessThanOrEqual)
     {
         Visit(node.Left);
         Visit(node.Right);
         var c = CreateCondition(ConditionType.LessthanEquals);
         if (condition == null)
         {
             condition = c;
         }
         if (currentNodes.Count > 0)
         {
             ((ConditionGroup)currentNodes.Peek()).Add(c);
         }
     }
     else if (node.NodeType == ExpressionType.GreaterThan)
     {
         Visit(node.Left);
         Visit(node.Right);
         var c = CreateCondition(ConditionType.Greater);
         if (condition == null)
         {
             condition = c;
         }
         if (currentNodes.Count > 0)
         {
             ((ConditionGroup)currentNodes.Peek()).Add(c);
         }
     }
     else if (node.NodeType == ExpressionType.GreaterThanOrEqual)
     {
         Visit(node.Left);
         Visit(node.Right);
         var c = CreateCondition(ConditionType.GreaterEquals);
         if (condition == null)
         {
             condition = c;
         }
         if (currentNodes.Count > 0)
         {
             ((ConditionGroup)currentNodes.Peek()).Add(c);
         }
     }
     else if (node.NodeType == ExpressionType.Equal)
     {
         Visit(node.Left);
         Visit(node.Right);
         var c = CreateCondition(parentXExpressionType.Count > 0 && parentXExpressionType.Peek() != ExpressionType.Not ? ConditionType.Equals : ConditionType.NotEquals);
         if (condition == null)
         {
             condition = c;
         }
         if (currentNodes.Count > 0)
         {
             ((ConditionGroup)currentNodes.Peek()).Add(c);
         }
     }
     else if (node.NodeType == ExpressionType.NotEqual)
     {
         Visit(node.Left);
         Visit(node.Right);
         var c = CreateCondition(parentXExpressionType.Count > 0 && parentXExpressionType.Peek() != ExpressionType.Not ? ConditionType.NotEquals : ConditionType.Equals);
         if (condition == null)
         {
             condition = c;
         }
         if (currentNodes.Count > 0)
         {
             ((ConditionGroup)currentNodes.Peek()).Add(c);
         }
     }
     else if (node.NodeType == ExpressionType.Add)
     {
         Visit(node.Left);
         Visit(node.Right);
         BEExpression expression = CreateExpression(Operator.Add);
         expressionPairs.Push(new BEExpressionValue()
         {
             Type = ExpressionValueType.Expression, Value = expression
         });
     }
     else if (node.NodeType == ExpressionType.Subtract)
     {
         Visit(node.Left);
         Visit(node.Right);
         BEExpression expression = CreateExpression(Operator.Subtract);
         expressionPairs.Push(new BEExpressionValue()
         {
             Type = ExpressionValueType.Expression, Value = expression
         });
     }
     else if (node.NodeType == ExpressionType.Multiply)
     {
         Visit(node.Left);
         Visit(node.Right);
         BEExpression expression = CreateExpression(Operator.Multiply);
         expressionPairs.Push(new BEExpressionValue()
         {
             Type = ExpressionValueType.Expression, Value = expression
         });
     }
     else if (node.NodeType == ExpressionType.Divide)
     {
         Visit(node.Left);
         Visit(node.Right);
         BEExpression expression = CreateExpression(Operator.Divide);
         expressionPairs.Push(new BEExpressionValue()
         {
             Type = ExpressionValueType.Expression, Value = expression
         });
     }
     else if (node.NodeType == ExpressionType.Modulo)
     {
         Visit(node.Left);
         Visit(node.Right);
         BEExpression expression = CreateExpression(Operator.Modulo);
         expressionPairs.Push(new BEExpressionValue()
         {
             Type = ExpressionValueType.Expression, Value = expression
         });
     }
     else if (node.NodeType == ExpressionType.Power)
     {
         Visit(node.Left);
         Visit(node.Right);
         BEExpression expression = CreateExpression(Operator.Power);
         expressionPairs.Push(new BEExpressionValue()
         {
             Type = ExpressionValueType.Expression, Value = expression
         });
     }
     else if (node.NodeType == ExpressionType.Call)
     {
         Visit(node.Left);
         Visit(node.Right);
         MakeCallExpression(node);
     }
     lastExpressionType = parentXExpressionType.Pop();
     return(node);
 }