コード例 #1
0
        public Expression ArithmeticUnaryExpression(ArithmeticUnaryExpression expression)
        {
            var result = expression.Expression.Visit(this);

            var literal = result as LiteralExpression;

            if (literal != null)
            {
                return(ResolveArithmeticUnaryLiteral(expression, literal));
            }

            return(new ArithmeticUnaryExpression(Operator.Negative, result));
        }
コード例 #2
0
        public override IProjection ArithmeticUnaryExpression(ArithmeticUnaryExpression expression)
        {
            var projection = CreateProjection(expression.Expression);

            switch (expression.Operator)
            {
            case Operator.Negative:
                return(new ArithmeticOperatorProjection(
                           "-",
                           DefaultArithmeticReturnType,
                           Projections.Constant(0),
                           projection
                           ));

            default:
                throw new NotSupportedException();
            }
        }
コード例 #3
0
        private Expression ResolveArithmeticUnaryLiteral(ArithmeticUnaryExpression expression, LiteralExpression literal)
        {
            if (expression.Operator != Operator.Negative)
            {
                throw new NotSupportedException();
            }

            object value = literal.Value;

            switch (literal.LiteralType)
            {
            case LiteralType.Decimal:
                value = -((decimal)value);
                break;

            case LiteralType.Double:
                value = -((double)value);
                break;

            case LiteralType.Duration:
                value = -((XmlTimeSpan)value);
                break;

            case LiteralType.Int:
                value = -((int)value);
                break;

            case LiteralType.Long:
                value = -((long)value);
                break;

            case LiteralType.Single:
                value = -((float)value);
                break;

            default:
                throw new ODataException(String.Format(
                                             ErrorMessages.Expression_CannotNegate, literal.LiteralType
                                             ));
            }

            return(new LiteralExpression(value, literal.LiteralType));
        }
コード例 #4
0
 public virtual T ArithmeticUnaryExpression(ArithmeticUnaryExpression expression)
 {
     throw new QueryNotSupportException();
 }
コード例 #5
0
 public Expression ArithmeticUnaryExpression(ArithmeticUnaryExpression expression)
 {
     return(new ArithmeticUnaryExpression(expression.Operator, expression.Expression.Visit(this)));
 }