Exemplo n.º 1
0
 private void WriteTokenIfReq(LinqExtender.Ast.LogicalExpression expression, Token token)
 {
     if (expression.IsChild)
     {
         WriteToken(token);
     }
 }
Exemplo n.º 2
0
        public override LinqExtender.Ast.Expression VisitLogicalExpression(LinqExtender.Ast.LogicalExpression expression)
        {
            WriteTokenIfReq(expression, Token.LeftParenthesis);

            this.Visit(expression.Left);

            WriteLogicalOperator(expression.Operator);

            this.Visit(expression.Right);

            WriteTokenIfReq(expression, Token.RightParentThesis);

            return(expression);
        }
Exemplo n.º 3
0
        internal override void ExecuteQuery(IBucket bucket, IModifiableCollection <T> items)
        {
            var fluentBucket    = FluentBucket.As(bucket);
            var expressionStack = new Stack <Ast.Expression>();

            var blockExpression = new Ast.BlockExpression();

            blockExpression.Expressions.Add(new Ast.TypeExpression(typeof(T)));

            if (fluentBucket.IsDirty)
            {
                var lambda = new Ast.LambdaExpression(typeof(T));

                fluentBucket.ExpressionTree
                .DescribeContainerAs(expressionStack)
                .Root((stack, operatorType) =>
                {
                    var logical = new Ast.LogicalExpression(operatorType);

                    var left = stack.Pop();

                    MarkAsChild(left);

                    logical.Left = left;
                    stack.Push(logical);
                })
                .EachLeaf((stack, item) =>
                {
                    var binary = new Ast.BinaryExpression(item.Operator)
                    {
                        Left  = new Ast.MemberExpression(item),
                        Right = new Ast.LiteralExpression(item.PropertyType, item.Value)
                    };

                    stack.Push(binary);
                })
                .End(stack =>
                {
                    var binary = stack.Pop();

                    if (stack.Count > 0 &&
                        stack.Peek().CodeType == CodeType.LogicalExpression)
                    {
                        var logical   = stack.Pop() as Ast.LogicalExpression;
                        logical.Right = binary;

                        // nested.
                        if (Peek(stack) as Ast.LogicalExpression != null)
                        {
                            MarkAsChild(logical);
                        }

                        stack.Push(logical);
                    }
                    else
                    {
                        stack.Push(binary);
                    }
                })
                .Execute();

                lambda.Body = expressionStack.Pop();
                blockExpression.Expressions.Add(lambda);
            }

            fluentBucket.Entity.OrderBy.IfUsed(() =>
                                               fluentBucket.Entity.OrderBy.ForEach.Process((member, asending) => {
                blockExpression.Expressions.Add(new Ast.OrderbyExpression(member, asending));
            }));

            fluentBucket.Method.ForEach((method) =>
            {
                blockExpression.Expressions.Add(new Ast.MethodCallExpression(method));
            });

            items.AddRange(Context.Execute(blockExpression));
        }
Exemplo n.º 4
0
 public virtual Expression VisitLogicalExpression(LogicalExpression expression)
 {
     this.Visit(expression.Left);
     this.Visit(expression.Right);
     return expression;
 }
Exemplo n.º 5
0
 public virtual Ast.Expression VisitLogicalExpression(Ast.LogicalExpression expression)
 {
     this.Visit(expression.Left);
     this.Visit(expression.Right);
     return(expression);
 }