Example #1
0
        public FilterExpression Translate(Expression expression)
        {
            Visit(expression);

            var expr = _filterExpressionParserStrategy.BuildExpression(_expression);

            return(expr);
        }
        public FilterExpression BuildExpression(Stack <Token> stack)
        {
            if (stack == null)
            {
                throw new ArgumentNullException("stack", "Cannot build binary expression from null expression stack.");
            }

            if (stack.Count < 1)
            {
                throw new ArgumentException("Cannot build binary expression from empty expression stack.");
            }

            var token = stack.Pop();

            if (token == null)
            {
                throw new ArgumentException("Cannot parse a null token.");
            }

            var op             = token.Value;
            var binaryOperator = op.GetFromODataQueryOperatorString();

            if (binaryOperator.IsBinaryOperator() == false)
            {
                throw new ArgumentException(String.Format("Could not create binary expression with operator '{0}'. It is not a binary operator.", binaryOperator));
            }

            var right = _filterExpressionParserStrategy.BuildExpression(stack);

            if (right == null)
            {
                throw new ArgumentException("Could not create binary expression with null right side.");
            }

            var left = _filterExpressionParserStrategy.BuildExpression(stack);

            if (left == null)
            {
                throw new ArgumentException("Could not create binary expression with null left side.");
            }

            var result = FilterExpression.Binary(left, binaryOperator, right);

            return(result);
        }
Example #3
0
        public FilterExpression BuildExpression(Stack <Token> stack)
        {
            // pop off the member access operator ('.')
            stack.Pop();

            var token = stack.Pop();

            var memberName = token.Value;

            var memberParent = _filterExpressionParserStrategy.BuildExpression(stack);

            var result = FilterExpression.MemberAccess(memberParent, memberName);

            return(result);
        }
        public FilterExpression BuildExpression(Stack <Token> stack)
        {
            if (stack == null)
            {
                throw new ArgumentNullException("stack", "Cannot build function expression with a null expression stack.");
            }

            if (stack.Count < 1)
            {
                throw new ArgumentException("Cannot build function expression for function '{0}'. Not enough parameters.");
            }

            var token = stack.Pop();

            if (token == null)
            {
                throw new ArgumentException("Cannot parse a null token.");
            }

            var function = token.Value.GetFromODataQueryMethodName();

            var arity = function.Arity();

            if (stack.Count < arity)
            {
                throw new ArgumentException(String.Format("Cannot build function expression for function '{0}'. Not enough parameters.", function));
            }

            var arguments = new List <FilterExpression>();

            for (int i = 0; i < arity; i++)
            {
                var argument = _filterExpressionParserStrategy.BuildExpression(stack);
                arguments.Add(argument);
            }

            arguments.Reverse();

            var result = FilterExpression.MethodCall(function, arguments.ToArray());

            return(result);
        }
Example #5
0
        public FilterExpression BuildExpression(Stack <Token> stack)
        {
            if (stack == null)
            {
                throw new ArgumentNullException("stack", "Cannot build unary expression from null expression stack.");
            }

            if (stack.Count < 1)
            {
                throw new ArgumentException("Cannot build unary expression from empty expression stack.");
            }

            var token = stack.Pop();

            if (token == null)
            {
                throw new ArgumentException("Cannot parse a null token.");
            }

            var op            = token.Value;
            var unaryOperator = op.GetFromODataQueryOperatorString();

            if (unaryOperator.IsUnaryOperator() == false)
            {
                throw new ArgumentException(String.Format("Cannot build unary expression with operator '{0}'. It is not a unary operator.", unaryOperator));
            }

            var operand = _filterExpressionParserStrategy.BuildExpression(stack);

            if (operand == null)
            {
                throw new ApplicationException("Cannot use a null operand when building a unary expression.");
            }

            var result = FilterExpression.Unary(unaryOperator, operand);

            return(result);
        }
Example #6
0
 public void BuildExpression_NullStack_ThrowsException()
 {
     Assert.That(() => _strategy.BuildExpression(null), Throws.InstanceOf <ArgumentNullException>());
 }