コード例 #1
0
        public override IList <SqlRuleProblem> Analyze(SqlRuleExecutionContext ruleExecutionContext)
        {
            var problems = new List <SqlRuleProblem>();
            var sqlObj   = ruleExecutionContext.ModelElement;

            if (sqlObj == null || sqlObj.IsWhiteListed())
            {
                return(problems);
            }

            var fragment = ruleExecutionContext.ScriptFragment.GetFragment(ProgrammingAndViewSchemaTypes);

            var whereClauseVisitor = new WhereClauseVisitor();

            fragment.Accept(whereClauseVisitor);

            foreach (var whereClause in whereClauseVisitor.Statements)
            {
                var binaryExpressionVisitor = new BinaryExpressionVisitor();
                whereClause.Accept(binaryExpressionVisitor);

                foreach (var comparison in binaryExpressionVisitor.NotIgnoredStatements(RuleId))
                {
                    if (CheckBinaryExpression(comparison).GetValueOrDefault(false))
                    {
                        problems.Add(new SqlRuleProblem(Message, sqlObj, comparison));
                    }
                }
            }

            return(problems);
        }
コード例 #2
0
            Token VisitBinaryNode(Expression node)
            {
                BinaryExpressionVisitor visitor = new BinaryExpressionVisitor(Context);

                visitor.Visit(node);
                return(visitor.Token);
            }
コード例 #3
0
    static void Main(string[] args)
    {
        Expression <Func <double, bool> > predicate = x => x > 3 && x > 4;
        var visitor = new BinaryExpressionVisitor();

        predicate = (Expression <Func <double, bool> >)visitor.Visit(predicate);
    }
コード例 #4
0
        protected override Expression VisitBinary(BinaryExpression node)
        {
            if (_operators.TryGetValue(node.NodeType, out var op))
            {
                var binary = new BinaryExpressionVisitor(this);
                _holder.Register(binary.BuildWhereFragment(node, op));

                return(null);
            }

            switch (node.NodeType)
            {
            case ExpressionType.AndAlso:
                buildCompoundWhereFragment(node, "and");
                break;

            case ExpressionType.OrElse:
                buildCompoundWhereFragment(node, "or");
                break;

            default:
                throw new BadLinqExpressionException($"Unsupported expression type '{node.NodeType}' in binary expression");
            }


            return(null);
        }
コード例 #5
0
 protected override Expression VisitBinary(BinaryExpression node)
 {
     BinaryExpressionVisitor visitor = new BinaryExpressionVisitor(Context);
     visitor.Visit(node);
     Token = visitor.Token;
     return node;
 }
コード例 #6
0
        static void AnalyzeBinaryExpression(SyntaxNodeAnalysisContext nodeContext)
        {
            var node    = nodeContext.Node as BinaryExpressionSyntax;
            var visitor = new BinaryExpressionVisitor(nodeContext);

            visitor.Visit(node);
        }
コード例 #7
0
            private Token VisitBinaryNode(Expression node)
            {
                if (node.NodeType == ExpressionType.Not)
                {
                    var token = VisitBinaryNode(((UnaryExpression)node).Operand);
                    switch (token.Type)
                    {
                    case TokenType.Column:
                    {
                        var condition1 = new Condition
                        {
                            Left        = token,
                            CompareType = CompareType.Not
                        };
                        return(Token.Create(condition1));
                    }

                    case TokenType.Object:
                        return(Token.Create(!(bool)token.Object));

                    case TokenType.Condition:
                        token.Condition.Right = Token.Create(0);
                        return(token);
                    }
                    throw new Exception();
                }
                if (node is MemberExpression)
                {
                    var visitor1 = new MemberExpressionVisitor(Context);
                    visitor1.Visit(node);
                    var token2 = visitor1.Token;
                    var type   = token2.Type;
                    if (type != TokenType.Column)
                    {
                        if (type != TokenType.Object)
                        {
                            throw new Exception();
                        }
                        return(token2);
                    }
                    if (TypeHelper.GetUnderlyingType(token2.Column.DataType) != ReflectorConsts.BoolType)
                    {
                        throw new Exception();
                    }
                    var token3     = token2;
                    var token4     = Token.Create(1);
                    var condition2 = new Condition
                    {
                        CompareType = CompareType.Equal,
                        Left        = token3,
                        Right       = token4
                    };
                    return(Token.Create(condition2));
                }
                var visitor2 = new BinaryExpressionVisitor(Context);

                visitor2.Visit(node);
                return(visitor2.Token);
            }
コード例 #8
0
        /// <summary>
        /// 解析二元表达式
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        protected override Expression VisitBinary(BinaryExpression node)
        {
            var binaryWhere = new BinaryExpressionVisitor(node, base.Provider);

            this._sqlCmd.Append(binaryWhere.SpliceField);
            base.Param.AddDynamicParams(binaryWhere.Param);
            return(node);
        }
コード例 #9
0
        /// <summary>
        /// 有+ - * /需要拼接的对象
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        protected override Expression VisitBinary(BinaryExpression node)
        {
            var binary = new BinaryExpressionVisitor(node, providerOption);

            SpliceField.Append(binary.SpliceField);
            this.Param.AddDynamicParams(binary.Param);
            return(node);
        }
コード例 #10
0
            protected override Expression VisitBinary(BinaryExpression node)
            {
                BinaryExpressionVisitor visitor = new BinaryExpressionVisitor(Context);

                visitor.Visit(node.Left);
                Token = visitor.Token;
                return(node);
            }
コード例 #11
0
        /// <summary>
        /// 有+ - * /需要拼接的对象
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        protected override Expression VisitBinary(BinaryExpression node)
        {
            var binary = new BinaryExpressionVisitor(node, providerOption, IsAsName);

            GenerateField(binary.SpliceField.ToString());
            this.Param.AddDynamicParams(binary.Param);
            return(node);
        }
コード例 #12
0
        static void AnalyzeBinaryExpression(OperationAnalysisContext nodeContext)
        {
            var node = (IBinaryOperation)nodeContext.Operation;

            if (node.OperatorKind == BinaryOperatorKind.Add)
            {
                var visitor = new BinaryExpressionVisitor(nodeContext);
                visitor.Visit(node);
            }
        }
        static void AnalyzeBinaryExpression(SyntaxNodeAnalysisContext nodeContext)
        {
            if (nodeContext.IsFromGeneratedCode())
            {
                return;
            }
            var node    = nodeContext.Node as BinaryExpressionSyntax;
            var visitor = new BinaryExpressionVisitor(nodeContext);

            visitor.Visit(node);
        }
コード例 #14
0
 Token ParseMathBinary(BinaryExpression node)
 {
     ExpressionVisitorBase leftVisitor, rightVisitor;
     if (node.Left is BinaryExpression)
     {
         leftVisitor = new BinaryExpressionVisitor(Context);
     }
     else
     {
         leftVisitor = new MemberExpressionVisitor(Context);
     }
     leftVisitor.Visit(node.Left);
     var leftResult = leftVisitor.Token;
     if (node.Right is BinaryExpression)
     {
         rightVisitor = new BinaryExpressionVisitor(Context);
     }
     else
     {
         rightVisitor = new MemberExpressionVisitor(Context);
     }
     rightVisitor.Visit(node.Right);
     var rightResult = rightVisitor.Token;
     if (leftResult.Type == TokenType.Object && rightResult.Type == TokenType.Object)
     {
         if (leftResult.Object == null && rightResult.Object == null)
         {
             return Token.Create(true);
         }
         if (leftResult == null || rightResult == null)
         {
             return Token.Create(false);
         }
         if (leftResult.Type == TokenType.Object)
         {
             if (leftResult.Object is string || leftResult.Object is bool || leftResult.Object is bool?)
             {
                 return Token.Create(leftResult.Equals(rightResult));
             }
             #region 比大小
             if (leftResult.Object is DateTime || leftResult.Object is DateTime?)
             {
                 var left = Convert.ToDateTime(leftResult.Object);
                 var right = Convert.ToDateTime(rightResult.Object);
                 switch (node.NodeType)
                 {
                     case ExpressionType.LessThan:
                         return Token.Create(left < right);
                     case ExpressionType.LessThanOrEqual:
                         return Token.Create(left <= right);
                     case ExpressionType.Equal:
                         return Token.Create(left = right);
                     case ExpressionType.GreaterThan:
                         return Token.Create(left > right);
                     case ExpressionType.GreaterThanOrEqual:
                         return Token.Create(left >= right);
                     default:
                         throw new Exception();
                 }
             }
             else if (leftResult.Object is int || leftResult.Object is int?)
             {
                 var left = Convert.ToInt32(leftResult.Object);
                 var right = Convert.ToInt32(rightResult.Object);
                 switch (node.NodeType)
                 {
                     case ExpressionType.LessThan:
                         return Token.Create(left < right);
                     case ExpressionType.LessThanOrEqual:
                         return Token.Create(left <= right);
                     case ExpressionType.Equal:
                         return Token.Create(left = right);
                     case ExpressionType.GreaterThan:
                         return Token.Create(left > right);
                     case ExpressionType.GreaterThanOrEqual:
                         return Token.Create(left >= right);
                     default:
                         throw new Exception();
                 }
             }
             else if (leftResult.Object is short || leftResult.Object is short?)
             {
                 var left = Convert.ToInt16(leftResult.Object);
                 var right = Convert.ToInt16(rightResult.Object);
                 switch (node.NodeType)
                 {
                     case ExpressionType.LessThan:
                         return Token.Create(left < right);
                     case ExpressionType.LessThanOrEqual:
                         return Token.Create(left <= right);
                     case ExpressionType.Equal:
                         return Token.Create(left = right);
                     case ExpressionType.GreaterThan:
                         return Token.Create(left > right);
                     case ExpressionType.GreaterThanOrEqual:
                         return Token.Create(left >= right);
                     default:
                         throw new Exception();
                 }
             }
             else if (leftResult.Object is long || leftResult.Object is long?)
             {
                 var left = Convert.ToInt64(leftResult.Object);
                 var right = Convert.ToInt64(rightResult.Object);
                 switch (node.NodeType)
                 {
                     case ExpressionType.LessThan:
                         return Token.Create(left < right);
                     case ExpressionType.LessThanOrEqual:
                         return Token.Create(left <= right);
                     case ExpressionType.Equal:
                         return Token.Create(left = right);
                     case ExpressionType.GreaterThan:
                         return Token.Create(left > right);
                     case ExpressionType.GreaterThanOrEqual:
                         return Token.Create(left >= right);
                     default:
                         throw new Exception();
                 }
             }
             else
             {
                 return Token.Create(leftResult.Object == rightResult.Object);
             }
             #endregion
         }
         else
         {
             throw new Exception();
         }
     }
     else if (leftResult.Type == TokenType.Column && rightResult.Type == TokenType.Object)
     {
         var condition = new Condition();
         condition.Left = leftResult;
         condition.CompareType = SelectMathCompareType(node.NodeType);
         condition.Right = Token.Create(rightResult.Object);
         return Token.Create(condition);
     }
     else if (leftResult.Type == TokenType.Condition && rightResult.Type == TokenType.Object)
     {
         var condition = new Condition();
         condition.Left = leftResult;
         condition.CompareType = SelectMathCompareType(node.NodeType);
         condition.Right = Token.Create(rightResult.Object);
         return Token.Create(condition);
     }
     else
     {
         throw new Exception();
     }
     throw new Exception();
 }
コード例 #15
0
 public GatherVisitor(BaseRefactoringContext context) : base(context)
 {
     binOpVisitor = new BinaryExpressionVisitor(this);
 }
コード例 #16
0
			public GatherVisitor (BaseRefactoringContext context) : base (context)
			{
				binOpVisitor = new BinaryExpressionVisitor (this);
			}
コード例 #17
0
 Token VisitBinaryNode(Expression node)
 {
     BinaryExpressionVisitor visitor = new BinaryExpressionVisitor(Context);
     visitor.Visit(node);
     return visitor.Token;
 }
コード例 #18
0
            Token ParseMathBinary(BinaryExpression node)
            {
                ExpressionVisitorBase leftVisitor, rightVisitor;

                if (node.Left is BinaryExpression)
                {
                    leftVisitor = new BinaryExpressionVisitor(Context);
                }
                else
                {
                    leftVisitor = new MemberExpressionVisitor(Context);
                }
                leftVisitor.Visit(node.Left);
                var leftResult = leftVisitor.Token;

                if (node.Right is BinaryExpression)
                {
                    rightVisitor = new BinaryExpressionVisitor(Context);
                }
                else
                {
                    rightVisitor = new MemberExpressionVisitor(Context);
                }
                rightVisitor.Visit(node.Right);
                var rightResult = rightVisitor.Token;

                if (leftResult.Type == TokenType.Object && rightResult.Type == TokenType.Object)
                {
                    if (leftResult.Object == null && rightResult.Object == null)
                    {
                        return(Token.Create(true));
                    }
                    if (leftResult == null || rightResult == null)
                    {
                        return(Token.Create(false));
                    }
                    if (leftResult.Type == TokenType.Object)
                    {
                        if (leftResult.Object is string || leftResult.Object is bool || leftResult.Object is bool?)
                        {
                            return(Token.Create(leftResult.Equals(rightResult)));
                        }
                        #region 比大小
                        if (leftResult.Object is DateTime || leftResult.Object is DateTime?)
                        {
                            var left  = Convert.ToDateTime(leftResult.Object);
                            var right = Convert.ToDateTime(rightResult.Object);
                            switch (node.NodeType)
                            {
                            case ExpressionType.LessThan:
                                return(Token.Create(left < right));

                            case ExpressionType.LessThanOrEqual:
                                return(Token.Create(left <= right));

                            case ExpressionType.Equal:
                                return(Token.Create(left = right));

                            case ExpressionType.GreaterThan:
                                return(Token.Create(left > right));

                            case ExpressionType.GreaterThanOrEqual:
                                return(Token.Create(left >= right));

                            default:
                                throw new Exception();
                            }
                        }
                        else if (leftResult.Object is int || leftResult.Object is int?)
                        {
                            var left  = Convert.ToInt32(leftResult.Object);
                            var right = Convert.ToInt32(rightResult.Object);
                            switch (node.NodeType)
                            {
                            case ExpressionType.LessThan:
                                return(Token.Create(left < right));

                            case ExpressionType.LessThanOrEqual:
                                return(Token.Create(left <= right));

                            case ExpressionType.Equal:
                                return(Token.Create(left = right));

                            case ExpressionType.GreaterThan:
                                return(Token.Create(left > right));

                            case ExpressionType.GreaterThanOrEqual:
                                return(Token.Create(left >= right));

                            default:
                                throw new Exception();
                            }
                        }
                        else if (leftResult.Object is short || leftResult.Object is short?)
                        {
                            var left  = Convert.ToInt16(leftResult.Object);
                            var right = Convert.ToInt16(rightResult.Object);
                            switch (node.NodeType)
                            {
                            case ExpressionType.LessThan:
                                return(Token.Create(left < right));

                            case ExpressionType.LessThanOrEqual:
                                return(Token.Create(left <= right));

                            case ExpressionType.Equal:
                                return(Token.Create(left = right));

                            case ExpressionType.GreaterThan:
                                return(Token.Create(left > right));

                            case ExpressionType.GreaterThanOrEqual:
                                return(Token.Create(left >= right));

                            default:
                                throw new Exception();
                            }
                        }
                        else if (leftResult.Object is long || leftResult.Object is long?)
                        {
                            var left  = Convert.ToInt64(leftResult.Object);
                            var right = Convert.ToInt64(rightResult.Object);
                            switch (node.NodeType)
                            {
                            case ExpressionType.LessThan:
                                return(Token.Create(left < right));

                            case ExpressionType.LessThanOrEqual:
                                return(Token.Create(left <= right));

                            case ExpressionType.Equal:
                                return(Token.Create(left = right));

                            case ExpressionType.GreaterThan:
                                return(Token.Create(left > right));

                            case ExpressionType.GreaterThanOrEqual:
                                return(Token.Create(left >= right));

                            default:
                                throw new Exception();
                            }
                        }
                        else
                        {
                            return(Token.Create(leftResult.Object == rightResult.Object));
                        }
                        #endregion
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else if (leftResult.Type == TokenType.Column && rightResult.Type == TokenType.Object)
                {
                    var condition = new Condition();
                    condition.Left        = leftResult;
                    condition.CompareType = SelectMathCompareType(node.NodeType);
                    condition.Right       = Token.Create(rightResult.Object);
                    return(Token.Create(condition));
                }
                else if (leftResult.Type == TokenType.Condition && rightResult.Type == TokenType.Object)
                {
                    var condition = new Condition();
                    condition.Left        = leftResult;
                    condition.CompareType = SelectMathCompareType(node.NodeType);
                    condition.Right       = Token.Create(rightResult.Object);
                    return(Token.Create(condition));
                }
                else
                {
                    throw new Exception();
                }
                throw new Exception();
            }
コード例 #19
0
 static void AnalyzeBinaryExpression(SyntaxNodeAnalysisContext nodeContext)
 {
     var node = nodeContext.Node as BinaryExpressionSyntax;
     var visitor = new BinaryExpressionVisitor(nodeContext);
     visitor.Visit(node);
 }
コード例 #20
0
            private Token ParseMathBinary(BinaryExpression node)
            {
                ExpressionVisitorBase base2;
                ExpressionVisitorBase base3;

                if (node.Left is BinaryExpression)
                {
                    base2 = new BinaryExpressionVisitor(Context);
                }
                else
                {
                    base2 = new MemberExpressionVisitor(Context);
                }
                base2.Visit(node.Left);
                var token = base2.Token;

                if (node.Right is BinaryExpression)
                {
                    base3 = new BinaryExpressionVisitor(Context);
                }
                else
                {
                    base3 = new MemberExpressionVisitor(Context);
                }
                base3.Visit(node.Right);
                var token2 = base3.Token;

                if ((token.Type != TokenType.Object) || (token2.Type != TokenType.Object))
                {
                    if ((token.Type == TokenType.Column) && (token2.Type == TokenType.Object))
                    {
                        var condition1 = new Condition
                        {
                            Left        = token,
                            CompareType = SelectMathCompareType(node.NodeType),
                            Right       = token2
                        };
                        return(Token.Create(condition1));
                    }
                    if ((token.Type != TokenType.Condition) || (token2.Type != TokenType.Object))
                    {
                        throw new Exception();
                    }
                    var condition2 = new Condition
                    {
                        Left        = token,
                        CompareType = SelectMathCompareType(node.NodeType),
                        Right       = token2
                    };
                    return(Token.Create(condition2));
                }
                if ((token.Object == null) && (token2.Object == null))
                {
                    return(Token.Create(true));
                }
                if ((token == null) || (token2 == null))
                {
                    return(Token.Create(false));
                }
                if (token.Type != TokenType.Object)
                {
                    throw new Exception();
                }
                if (token.Object is string || token.Object is bool || token.Object is bool?)
                {
                    return(Token.Create(token.Equals(token2)));
                }
                if (!(token.Object is DateTime) && !(token.Object is DateTime?))
                {
                    if (!(token.Object is int) && !(token.Object is int?))
                    {
                        if (!(token.Object is short) && !(token.Object is short?))
                        {
                            if (!(token.Object is long) && !(token.Object is long?))
                            {
                                return(Token.Create(token.Object == token2.Object));
                            }
                            var num5 = Convert.ToInt64(token.Object);
                            var num6 = Convert.ToInt64(token2.Object);
                            switch (node.NodeType)
                            {
                            case ExpressionType.Equal:
                                return(Token.Create(num5 = num6));

                            case ExpressionType.GreaterThan:
                                return(Token.Create(num5 > num6));

                            case ExpressionType.GreaterThanOrEqual:
                                return(Token.Create(num5 >= num6));

                            case ExpressionType.LessThan:
                                return(Token.Create(num5 < num6));

                            case ExpressionType.LessThanOrEqual:
                                return(Token.Create(num5 <= num6));
                            }
                            throw new Exception();
                        }
                        var num3 = Convert.ToInt16(token.Object);
                        var num4 = Convert.ToInt16(token2.Object);
                        switch (node.NodeType)
                        {
                        case ExpressionType.Equal:
                            return(Token.Create(num3 = num4));

                        case ExpressionType.GreaterThan:
                            return(Token.Create(num3 > num4));

                        case ExpressionType.GreaterThanOrEqual:
                            return(Token.Create(num3 >= num4));

                        case ExpressionType.LessThan:
                            return(Token.Create(num3 < num4));

                        case ExpressionType.LessThanOrEqual:
                            return(Token.Create(num3 <= num4));
                        }
                        throw new Exception();
                    }
                    var num  = Convert.ToInt32(token.Object);
                    var num2 = Convert.ToInt32(token2.Object);
                    switch (node.NodeType)
                    {
                    case ExpressionType.Equal:
                        return(Token.Create(num = num2));

                    case ExpressionType.GreaterThan:
                        return(Token.Create(num > num2));

                    case ExpressionType.GreaterThanOrEqual:
                        return(Token.Create(num >= num2));

                    case ExpressionType.LessThan:
                        return(Token.Create(num < num2));

                    case ExpressionType.LessThanOrEqual:
                        return(Token.Create(num <= num2));
                    }
                    throw new Exception();
                }
                var time  = Convert.ToDateTime(token.Object);
                var time2 = Convert.ToDateTime(token2.Object);

                switch (node.NodeType)
                {
                case ExpressionType.Equal:
                    return(Token.Create(time = time2));

                case ExpressionType.GreaterThan:
                    return(Token.Create(time > time2));

                case ExpressionType.GreaterThanOrEqual:
                    return(Token.Create(time >= time2));

                case ExpressionType.LessThan:
                    return(Token.Create(time < time2));

                case ExpressionType.LessThanOrEqual:
                    return(Token.Create(time <= time2));
                }
                throw new Exception();
            }