Beispiel #1
0
            public override void Visit(SqlBinaryExpression expression)
            {
                bool useParentheses = expression.Operator == SqlBinaryOperator.And ||
                                      expression.Operator == SqlBinaryOperator.Or;

                // TODO: The accept code should be in the class itself.
                if (useParentheses)
                {
                    _writer.WriteOpenParenthesis();
                }
                expression.Left.Accept(this);
                if (useParentheses)
                {
                    _writer.WriteCloseParenthesis();
                }
                expression.Operator.Accept(this);
                if (useParentheses)
                {
                    _writer.WriteOpenParenthesis();
                }
                expression.Right.Accept(this);
                if (useParentheses)
                {
                    _writer.WriteCloseParenthesis();
                }
            }
Beispiel #2
0
 /// <summary>
 /// Creates a <see cref="SqlBinaryExpression"/> that represents a logical <b>AND</b> operation.
 /// </summary>
 /// <param name="left">
 /// A <see cref="SqlBinaryExpression"/> to use as the left operand in the expression.
 /// </param>
 /// <param name="right">
 /// A <see cref="SqlBinaryExpression"/> to use as the right operand in the expression.
 /// </param>
 /// <returns>
 /// A <see cref="SqlBinaryExpression"/> that represents a logical <b>AND</b> operation between
 /// the specified <paramref name="left"/> and <paramref name="right"/> operands.
 /// </returns>
 public static SqlBinaryExpression And(SqlBinaryExpression left, SqlBinaryExpression right)
 {
     return new SqlBinaryExpression(left, SqlBinaryOperator.And, right);
 }
Beispiel #3
0
 /// <summary>
 /// Creates a <see cref="SqlBinaryExpression"/> that represents a logical <b>OR</b> operation.
 /// </summary>
 /// <param name="left">
 /// A <see cref="SqlBinaryExpression"/> to use as the left operand in the expression.
 /// </param>
 /// <param name="right">
 /// A <see cref="SqlBinaryExpression"/> to use as the right operand in the expression.
 /// </param>
 /// <returns>
 /// A <see cref="SqlBinaryExpression"/> that represents a logical <b>OR</b> operation between
 /// the specified <paramref name="left"/> and <paramref name="right"/> operands.
 /// </returns>
 public static SqlBinaryExpression Or(SqlBinaryExpression left, SqlBinaryExpression right)
 {
     return(new SqlBinaryExpression(left, SqlBinaryOperator.Or, right));
 }
            protected override SqlExpression VisitBinary(SqlBinaryExpression expression)
            {
                switch (expression.Operator)
                {
                    case SqlBinaryOperator.And:
                    case SqlBinaryOperator.Or:
                        _writer.WriteOpenParenthesis();
                        Visit(expression.Left);
                        break;

                    default:
                        Visit(expression.Left);
                        break;
                }

                _writer.WriteOperator(expression.Operator);

                switch (expression.Operator)
                {
                    case SqlBinaryOperator.And:
                    case SqlBinaryOperator.Or:
                        Visit(expression.Right);
                        _writer.WriteCloseParenthesis();
                        break;

                    default:
                        Visit(expression.Right);
                        break;
                }

                return expression;
            }