Accept() public method

public Accept ( SqlExpressionVisitor visitor ) : SqlExpression
visitor SqlExpressionVisitor
return SqlExpression
Beispiel #1
0
        private static void Visit(SqlExpression exp, bool equals = false)
        {
            var visitor = new SqlExpressionVisitor();
            var result  = exp.Accept(visitor);

            Assert.IsType(exp.GetType(), result);
            Assert.Equal(equals, result.Equals(exp));

            result = visitor.Visit(exp);
            Assert.IsType(exp.GetType(), result);
            Assert.Equal(equals, result.Equals(exp));
        }
        /// <summary>
        /// Visits a given SQL expression.
        /// </summary>
        /// <param name="expression">The <see cref="SqlExpression"/> to visit.</param>
        /// <returns>
        /// Returns an instance of <see cref="SqlExpression"/> as result of the visit.
        /// </returns>
        public virtual SqlExpression Visit(SqlExpression expression)
        {
            if (expression == null)
                return null;

            var expressionType = expression.ExpressionType;
            switch (expressionType) {
                case SqlExpressionType.Add:
                case SqlExpressionType.Subtract:
                case SqlExpressionType.Divide:
                case SqlExpressionType.Multiply:
                case SqlExpressionType.Modulo:
                case SqlExpressionType.And:
                case SqlExpressionType.Or:
                case SqlExpressionType.XOr:
                case SqlExpressionType.Equal:
                case SqlExpressionType.NotEqual:
                case SqlExpressionType.Like:
                case SqlExpressionType.NotLike:
                case SqlExpressionType.GreaterThan:
                case SqlExpressionType.GreaterOrEqualThan:
                case SqlExpressionType.SmallerThan:
                case SqlExpressionType.SmallerOrEqualThan:
                case SqlExpressionType.Is:
                case SqlExpressionType.IsNot:
                    return VisitBinary((SqlBinaryExpression) expression);
                case SqlExpressionType.Negate:
                case SqlExpressionType.Not:
                case SqlExpressionType.UnaryPlus:
                    return VisitUnary((SqlUnaryExpression) expression);
                case SqlExpressionType.Cast:
                    return VisitCast((SqlCastExpression) expression);
                case SqlExpressionType.Reference:
                    return VisitReference((SqlReferenceExpression) expression);
                case SqlExpressionType.VariableReference:
                    return VisitVariableReference((SqlVariableReferenceExpression) expression);
                case SqlExpressionType.Assign:
                    return VisitAssign((SqlAssignExpression) expression);
                case SqlExpressionType.FunctionCall:
                    return VisitFunctionCall((SqlFunctionCallExpression) expression);
                case SqlExpressionType.Constant:
                    return VisitConstant((SqlConstantExpression) expression);
                case SqlExpressionType.Conditional:
                    return VisitConditional((SqlConditionalExpression) expression);
                case SqlExpressionType.Query:
                    return VisitQuery((SqlQueryExpression) expression);
                case SqlExpressionType.Tuple:
                    return VisitTuple((SqlTupleExpression) expression);
                case SqlExpressionType.All:
                case SqlExpressionType.Any:
                    return VisitQuantified((SqlQuantifiedExpression) expression);
                default:
                    return expression.Accept(this);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Visits a given SQL expression.
        /// </summary>
        /// <param name="expression">The <see cref="SqlExpression"/> to visit.</param>
        /// <returns>
        /// Returns an instance of <see cref="SqlExpression"/> as result of the visit.
        /// </returns>
        public virtual SqlExpression Visit(SqlExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            var expressionType = expression.ExpressionType;

            switch (expressionType)
            {
            case SqlExpressionType.Add:
            case SqlExpressionType.Subtract:
            case SqlExpressionType.Divide:
            case SqlExpressionType.Multiply:
            case SqlExpressionType.Modulo:
            case SqlExpressionType.And:
            case SqlExpressionType.Or:
            case SqlExpressionType.XOr:
            case SqlExpressionType.Equal:
            case SqlExpressionType.NotEqual:
            case SqlExpressionType.Like:
            case SqlExpressionType.NotLike:
            case SqlExpressionType.GreaterThan:
            case SqlExpressionType.GreaterOrEqualThan:
            case SqlExpressionType.SmallerThan:
            case SqlExpressionType.SmallerOrEqualThan:
            case SqlExpressionType.Is:
            case SqlExpressionType.IsNot:
            case SqlExpressionType.AllEqual:
            case SqlExpressionType.AllNotEqual:
            case SqlExpressionType.AllGreaterThan:
            case SqlExpressionType.AllSmallerThan:
            case SqlExpressionType.AllGreaterOrEqualThan:
            case SqlExpressionType.AllSmallerOrEqualThan:
            case SqlExpressionType.AnyEqual:
            case SqlExpressionType.AnyNotEqual:
            case SqlExpressionType.AnyGreaterThan:
            case SqlExpressionType.AnySmallerThan:
            case SqlExpressionType.AnyGreaterOrEqualThan:
            case SqlExpressionType.AnySmallerOrEqualThan:
                return(VisitBinary((SqlBinaryExpression)expression));

            case SqlExpressionType.Negate:
            case SqlExpressionType.Not:
            case SqlExpressionType.UnaryPlus:
                return(VisitUnary((SqlUnaryExpression)expression));

            case SqlExpressionType.Cast:
                return(VisitCast((SqlCastExpression)expression));

            case SqlExpressionType.Reference:
                return(VisitReference((SqlReferenceExpression)expression));

            case SqlExpressionType.VariableReference:
                return(VisitVariableReference((SqlVariableReferenceExpression)expression));

            case SqlExpressionType.Assign:
                return(VisitAssign((SqlAssignExpression)expression));

            case SqlExpressionType.FunctionCall:
                return(VisitFunctionCall((SqlFunctionCallExpression)expression));

            case SqlExpressionType.Constant:
                return(VisitConstant((SqlConstantExpression)expression));

            case SqlExpressionType.Conditional:
                return(VisitConditional((SqlConditionalExpression)expression));

            case SqlExpressionType.Query:
                return(VisitQuery((SqlQueryExpression)expression));

            case SqlExpressionType.Tuple:
                return(VisitTuple((SqlTupleExpression)expression));

            default:
                return(expression.Accept(this));
            }
        }