Ejemplo n.º 1
0
        private QueryClause VisitSelectMany(MethodCallExpression node, LambdaExpression selector, LambdaExpression projector)
        {
            if (projector != selector)
            {
                Type transparentType = projector.ReturnType;

                if (transparentType.IsCompilerGenerated())
                {
                    // from {item1} in {collection1}
                    // from {item2} in {collection2}
                    ParameterExpression firstVar  = GetVariable(projector.Parameters[0]);
                    ParameterExpression secondVar = GetVariable(projector.Parameters[1]);

                    _clauses.Add(Expressive.From(firstVar, node.Arguments[0]));

                    return(Expressive.From(secondVar, selector.Body));
                }
                else
                {
                    // from {item} in {collection}
                    // select {item}
                    ParameterExpression newItem = GetVariable(projector.Parameters[1]);

                    _clauses.Add(Expressive.From(newItem, selector.Body));

                    return(Expressive.Select(projector.Body));
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
 /// <inheritdoc />
 public override Expression VisitLockStatement(ILockStatement operation, LocalBinder argument)
 {
     return(Expressive.Lock(
                operation.LockedObject.Accept(this, argument),
                operation.Body.Accept(this, argument)
                ));
 }
Ejemplo n.º 3
0
 /// <inheritdoc />
 public override Expression VisitQueryExpression(QueryExpressionSyntax node)
 {
     return(Expressive.Query(
                Enumerable.Repeat(VisitContinuationClause(node.FromClause), 1)
                .Concat(VisitLinqBody(node.Body))
                ));
 }
Ejemplo n.º 4
0
 /// <inheritdoc />
 public override Expression VisitUsingStatement(IUsingStatement operation, LocalBinder argument)
 {
     // TODO: Declarations in new binder
     return(Expressive.Using(
                Visit(operation.Declaration ?? operation.Value, argument),
                operation.Body.Accept(this, argument)
                ));
 }
Ejemplo n.º 5
0
 /// <inheritdoc />
 protected override Expression Reduce(QueryClause previous, QueryClause next)
 {
     return(Expressive.ForEach(
                Variable,
                Enumerable,
                next.Reduce()
                ));
 }
Ejemplo n.º 6
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public OrderByClause Update(IEnumerable <OrderingExpression> orderings)
        {
            if (orderings.SequenceEqual(Orderings))
            {
                return(this);
            }

            return(Expressive.OrderBy(orderings));
        }
Ejemplo n.º 7
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public LockExpression Update(Expression obj, Expression body)
        {
            if (body == Body && obj == Object)
            {
                return(this);
            }

            return(Expressive.Lock(obj, body));
        }
Ejemplo n.º 8
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public WhereClause Update(Expression condition)
        {
            if (Condition == condition)
            {
                return(this);
            }

            return(Expressive.Where(condition));
        }
Ejemplo n.º 9
0
        /// <inheritdoc cref="UnaryExpression.Update(System.Linq.Expressions.Expression)" select="summary"/>
        public AwaitExpression Update(Expression task, MethodInfo method)
        {
            if (Expression == task && Equals(Method, method))
            {
                return(this);
            }

            return(Expressive.Await(task, method));
        }
Ejemplo n.º 10
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public SelectClause Update(Expression expression)
        {
            if (Selector == expression)
            {
                return(this);
            }

            return(Expressive.Select(expression));
        }
Ejemplo n.º 11
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public FromClause Update(ParameterExpression variable, Expression enumerable)
        {
            if (Variable == variable && Enumerable == enumerable)
            {
                return(this);
            }

            return(Expressive.From(variable, enumerable));
        }
Ejemplo n.º 12
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public GroupByClause Update(ParameterExpression variable, Expression selector)
        {
            if (Variable == variable && Selector == selector)
            {
                return(this);
            }

            return(Expressive.GroupBy(variable, selector));
        }
Ejemplo n.º 13
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public JoinClause Update(ParameterExpression variable, Expression enumerable, Expression left, Expression right)
        {
            if (Variable == variable && Enumerable == enumerable && Left == left && Right == right)
            {
                return(this);
            }

            return(Expressive.Join(variable, enumerable, left, right));
        }
Ejemplo n.º 14
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public LetClause Update(ParameterExpression variable, Expression expression)
        {
            if (Variable == variable && Expression == expression)
            {
                return(this);
            }

            return(Expressive.Let(variable, expression));
        }
Ejemplo n.º 15
0
        private QueryClause VisitWhere(MethodCallExpression node, LambdaExpression predicate)
        {
            if (_clauses.Count == 0)
            {
                _clauses.Add(Expressive.From(GetVariable(predicate.Parameters[0]), node.Arguments[0]));
            }

            return(Expressive.Where(predicate.Body));
        }
Ejemplo n.º 16
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public ForExpression Update(ParameterExpression variable, Expression initializer, Expression test, Expression step, Expression body, LabelTarget breakTarget, LabelTarget continueTarget)
        {
            if (Variable == variable && Initializer == initializer && Test == test && Step == step && Body == body && BreakLabel == breakTarget && ContinueLabel == continueTarget)
            {
                return(this);
            }

            return(Expressive.For(variable, initializer, test, step, body, breakTarget, continueTarget));
        }
Ejemplo n.º 17
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public ForEachExpression Update(ParameterExpression variable, Expression enumerable, Expression body, LabelTarget breakTarget, LabelTarget continueTarget)
        {
            if (this.Variable == variable && this.Enumerable == enumerable && this.Body == body && BreakLabel == breakTarget && ContinueLabel == continueTarget)
            {
                return(this);
            }

            return(Expressive.ForEach(variable, enumerable, body, breakTarget, continueTarget));
        }
Ejemplo n.º 18
0
        private QueryClause VisitOrderBy(MethodCallExpression node, LambdaExpression lambda, bool descending)
        {
            if (_clauses.Count == 0)
            {
                _clauses.Add(Expressive.From(GetVariable(lambda.Parameters[1]), node.Arguments[0]));
            }

            return(Expressive.OrderBy(lambda.Body, !descending));
        }
Ejemplo n.º 19
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public AsyncExpression Update(Expression body)
        {
            if (Body == body)
            {
                return(this);
            }

            return(Expressive.Async(body));
        }
Ejemplo n.º 20
0
        /// <inheritdoc />
        public override Expression VisitWhileUntilLoopStatement(IWhileUntilLoopStatement operation, LocalBinder argument)
        {
            Expression condition = operation.Condition.Accept(this, argument);
            Expression body      = operation.Body.Accept(this, argument);

            return(operation.IsTopTest
                ? Expressive.While(condition, body) as Expression
                : Expressive.DoWhile(condition, body));
        }
Ejemplo n.º 21
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public QueryExpression Update(params QueryClause[] clauses)
        {
            if (Clauses.SequenceEqual(clauses))
            {
                return(this);
            }

            return(Expressive.Query(clauses));
        }
Ejemplo n.º 22
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public DoWhileExpression Update(Expression test, Expression body, LabelTarget breakTarget, LabelTarget continueTarget)
        {
            if (Test == test && Body == body && BreakLabel == breakTarget && ContinueLabel == continueTarget)
            {
                return(this);
            }

            return(Expressive.DoWhile(test, body, breakTarget, continueTarget));
        }
Ejemplo n.º 23
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public UsingExpression Update(ParameterExpression variable, Expression disposable, Expression body)
        {
            if (Variable == variable && Disposable == disposable && Body == body)
            {
                return(this);
            }

            return(Expressive.Using(variable, disposable, body));
        }
Ejemplo n.º 24
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public IteratorExpression Update(Expression iterator)
        {
            if (Iterator == iterator)
            {
                return(this);
            }

            return(Expressive.Iterator(iterator));
        }
Ejemplo n.º 25
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public TypeOfExpression Update(Type type)
        {
            if (TargetType == type)
            {
                return(this);
            }

            return(Expressive.TypeOf(type));
        }
Ejemplo n.º 26
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public WhileExpression Update(Expression test, Expression body, LabelTarget breakTarget, LabelTarget continueTarget)
        {
            if (test == Test && body == Body && breakTarget == BreakLabel && continueTarget == ContinueLabel)
            {
                return(this);
            }

            return(Expressive.While(test, body, breakTarget, continueTarget));
        }
Ejemplo n.º 27
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public TypeExpression Update(Type type)
        {
            if (Type == type)
            {
                return(this);
            }

            return(Expressive.Type(type));
        }
Ejemplo n.º 28
0
        /// <inheritdoc cref="UnaryExpression.Update(System.Linq.Expressions.Expression)" select="summary"/>
        public YieldExpression Update(Expression value)
        {
            if (Expression == value)
            {
                return(this);
            }

            return(Expressive.Yield(value));
        }
Ejemplo n.º 29
0
        /// <inheritdoc cref="UnaryExpression.Update(Expression)" select="summary"/>
        public GroupByIntoClause Update(ParameterExpression variable, Expression selector, ParameterExpression group)
        {
            if (Variable == variable && Selector == selector && Group == group)
            {
                return(this);
            }

            return(Expressive.GroupBy(variable, selector, group));
        }
Ejemplo n.º 30
0
        /// <inheritdoc />
        public override Expression VisitForEachLoopStatement(IForEachLoopStatement operation, LocalBinder argument)
        {
            ParameterExpression variable = VisitLocal(operation.IterationVariable);
            LocalBinder         binder   = argument.Child(operation.IterationVariable, variable);

            return(Expressive.ForEach(variable,
                                      operation.Collection.Accept(this, argument),
                                      operation.Body.Accept(this, binder)
                                      ));
        }