Exemplo n.º 1
0
 protected void VisitNewArray(NewArrayExpression node, TState state, params Expression[] expressionsNotToVisit)
 {
     ValidateArguments(node);
     if (node.Expressions != null)
     {
         Visit(Context.Create(node, state), Queryable.Except(node.Expressions, expressionsNotToVisit));
     }
 }
Exemplo n.º 2
0
 protected void VisitRuntimeVariables(RuntimeVariablesExpression node, TState state, params ParameterExpression[] variablesNotToVisit)
 {
     ValidateArguments(node);
     if (node.Variables != null)
     {
         Visit(Context.Create(node, state), Queryable.Except(node.Variables, variablesNotToVisit), Visit);
     }
 }
Exemplo n.º 3
0
 protected void VisitMemberListBinding(MemberListBinding node, TState state, params ElementInit[] initializersNotToVisit)
 {
     ValidateArguments(node);
     if (node.Initializers != null)
     {
         Visit(Context.Create(node, state), Queryable.Except(node.Initializers, initializersNotToVisit), VisitElementInit);
     }
 }
Exemplo n.º 4
0
 protected void VisitMemberMemberBinding(MemberMemberBinding node, TState state, params MemberBinding[] memberBindingsNotToVisit)
 {
     ValidateArguments(node);
     if (node.Bindings != null)
     {
         Visit(Context.Create(node, state), Queryable.Except(node.Bindings, memberBindingsNotToVisit), VisitMemberBinding);
     }
 }
Exemplo n.º 5
0
 protected void VisitElementInit(ElementInit node, TState state, params Expression[] argsNotToVisit)
 {
     ValidateArguments(node);
     if (node.Arguments != null)
     {
         Visit(Context.Create(node, state), Queryable.Except(node.Arguments, argsNotToVisit), Visit);
     }
 }
Exemplo n.º 6
0
 protected void VisitSwitchCase(SwitchCase node, TState testValuesState, TState bodyState, bool visitTestValues, bool visitBody, params Expression[] testValuesNotToVisit)
 {
     ValidateArguments(node);
     if (visitTestValues && node.TestValues != null)
     {
         Visit(Context.Create(node, testValuesState), Queryable.Except(node.TestValues, testValuesNotToVisit));
     }
     if (visitBody && node.Body != null)
     {
         Visit(Context.Create(node, bodyState), node.Body);
     }
 }
Exemplo n.º 7
0
 protected void VisitMemberInit(MemberInitExpression node, TState newExpressionState, TState bindingsState, bool visitNewExpression, bool visitBindings, params MemberBinding[] bindingsNotToVisit)
 {
     ValidateArguments(node);
     if (visitNewExpression && node.NewExpression != null)
     {
         Visit(Context.Create(node, newExpressionState), node.NewExpression);
     }
     if (visitBindings && node.Bindings != null)
     {
         Visit(Context.Create(node, bindingsState), Queryable.Except(node.Bindings, bindingsNotToVisit), VisitMemberBinding);
     }
 }
Exemplo n.º 8
0
 protected void VisitListInit(ListInitExpression node, TState newExpressionState, TState initializerState, bool visitNewExpression, bool visitInitializers, params ElementInit[] initializersNotToVisit)
 {
     ValidateArguments(node);
     if (visitNewExpression && node.NewExpression != null)
     {
         Visit(Context.Create(node, newExpressionState), node.NewExpression);
     }
     if (visitInitializers && node.Initializers != null)
     {
         Visit(Context.Create(node, initializerState), Queryable.Except(node.Initializers, initializersNotToVisit), VisitElementInit);
     }
 }
Exemplo n.º 9
0
 protected void VisitLambda(LambdaExpression node, TState bodyState, TState parametersState, bool visitBody, bool visitParameters, params ParameterExpression[] paramsNotToVisit)
 {
     ValidateArguments(node);
     if (visitBody && node.Body != null)
     {
         Visit(Context.Create(node, bodyState), node.Body);
     }
     if (visitParameters && node.Parameters != null)
     {
         Visit(Context.Create(node, parametersState), Queryable.Except(node.Parameters, paramsNotToVisit), Visit);
     }
 }
Exemplo n.º 10
0
 protected void VisitInvocation(InvocationExpression node, TState expressionState, TState argumentsState, bool visitExpression, bool visitArguments, params Expression[] argsNotToVisit)
 {
     ValidateArguments(node);
     if (visitExpression && node.Expression != null)
     {
         Visit(Context.Create(node, expressionState), node.Expression);
     }
     if (visitArguments && node.Arguments != null)
     {
         Visit(Context.Create(node, argumentsState), Queryable.Except(node.Arguments, argsNotToVisit), Visit);
     }
 }
Exemplo n.º 11
0
 protected void VisitIndex(IndexExpression node, TState objectState, TState argumentsState, bool visitObject, bool visitArguments, params Expression[] argsNotToVisit)
 {
     ValidateArguments(node);
     if (visitObject && node.Object != null)
     {
         Visit(Context.Create(node, objectState), node.Object);
     }
     if (visitArguments && node.Arguments != null)
     {
         Visit(Context.Create(node, argumentsState), Queryable.Except(node.Arguments, argsNotToVisit), Visit);
     }
 }
Exemplo n.º 12
0
 protected void VisitBlock(BlockExpression node, TState expressionsState, TState variablesState,
                           bool visitExpressions, bool visitVariables,
                           IEnumerable <Expression> expressionsNotToVisit,
                           IEnumerable <ParameterExpression> variablesNotToVisit)
 {
     ValidateArguments(node);
     if (visitExpressions && node.Expressions != null)
     {
         Visit(Context.Create(node, expressionsState), Queryable.Except(node.Expressions, expressionsNotToVisit));
     }
     if (visitVariables && node.Variables != null)
     {
         Visit(Context.Create(node, variablesState), Queryable.Except(node.Variables, variablesNotToVisit));
     }
 }
Exemplo n.º 13
0
 protected void VisitSwitch(SwitchExpression node, TState switchValueState, TState switchCasesState, TState defaultBodyState, bool visitSwitchValue, bool visitSwitchCases, bool visitDefaultBody, params SwitchCase[] switchCasesNotToVisit)
 {
     ValidateArguments(node);
     if (visitSwitchValue && node.SwitchValue != null)
     {
         Visit(Context.Create(node, switchValueState), node.SwitchValue);
     }
     if (visitSwitchCases && node.Cases != null)
     {
         Visit(Context.Create(node, switchCasesState), Queryable.Except(node.Cases, switchCasesNotToVisit), VisitSwitchCase);
     }
     if (visitDefaultBody && node.DefaultBody != null)
     {
         Visit(Context.Create(node, defaultBodyState), node.DefaultBody);
     }
 }
Exemplo n.º 14
0
 protected void VisitTry(TryExpression node, TState bodyState, TState handlersState, TState finallyState, TState faultState, bool visitBody, bool visitHandlers, bool visitFinally, bool visitFault, params CatchBlock[] catchBlocksNotToVisit)
 {
     ValidateArguments(node);
     if (visitBody && node.Body != null)
     {
         Visit(Context.Create(node, bodyState), node.Body);
     }
     if (visitHandlers && node.Handlers != null)
     {
         Visit(Context.Create(node, handlersState), Queryable.Except(node.Handlers, catchBlocksNotToVisit), VisitCatchBlock);
     }
     if (visitFinally && node.Finally != null)
     {
         Visit(Context.Create(node, finallyState), node.Finally);
     }
     if (visitFault && node.Fault != null)
     {
         Visit(Context.Create(node, faultState), node.Fault);
     }
 }
Exemplo n.º 15
0
        protected override void VisitMethodCall(Context context, MethodCallExpression node)
        {
            var query = context.State;

            if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Union(Enumerable.Empty <T>())))
            {
                AddSourceQuery(query.Select, CreateModel(node.ArgumentAt(2), _getTableName).Select);
            }
            else if (query.Select.From.HasQueries)
            {
                // If we have unions we need to nest subsequent query operators otherwise they would apply to the
                // net result of the union. This is consistent with the behavior of linq to objects.
                AddSourceQuery(query.Select, CreateModel(node, _getTableName).Select);
                return;
            }
            else
            {
                if (node.MatchesMethodSignature <IQueryable <T> >(x => x.CopyTo(Queryable.Empty <T>())))
                {
                    HandleSelectInto(query, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Where(y => true)))
                {
                    HandleWhere(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Distinct(y => y)))
                {
                    HandleDistinct(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Distinct(y => y, y => y, Order.Ascending)))
                {
                    HandleDistinct(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Duplicates(y => y)))
                {
                    HandleDuplicates(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Duplicates(y => y, y => y, Order.Ascending)))
                {
                    HandleDuplicates(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Duplicates(y => y, y => y, Order.Ascending, y => y, Order.Ascending)))
                {
                    HandleDuplicates(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.OrderBy(y => y)))
                {
                    HandleOrderBy(query.Select, node, false);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.OrderByDescending(y => y)))
                {
                    HandleOrderBy(query.Select, node, true);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Take(0)))
                {
                    query.Select.Top = node.ConstantArgumentAt <int>(2); query.Select.TopType = Select.TopValueType.Count;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.TakePercent(0)))
                {
                    query.Select.Top = node.ConstantArgumentAt <int>(2); query.Select.TopType = Select.TopValueType.Percent;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Skip(0)))
                {
                    query.Select.Start = node.ConstantArgumentAt <int>(2) + 1;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Single()))
                {
                    query.Select.Single = true;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Single(y => true)))
                {
                    query.Select.Single = true; HandleWhere(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.First()))
                {
                    query.Select.First = true;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.First(y => true)))
                {
                    query.Select.First = true; HandleWhere(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.FirstOrDefault()))
                {
                    query.Select.FirstOrDefault = true;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.FirstOrDefault(y => true)))
                {
                    query.Select.FirstOrDefault = true; HandleWhere(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Any()))
                {
                    query.Select.Any = true;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Any(y => true)))
                {
                    query.Select.Any = true; HandleWhere(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Count()))
                {
                    query.Select.Count = true;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Count(y => true)))
                {
                    query.Select.Count = true; HandleWhere(query.Select, node);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Randomize()))
                {
                    query.Select.Randomize = true;
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Intersect(
                                                                           Queryable.Empty <T>(), new Expression <Func <T, object> >[] { })))
                {
                    HandleSetOperation(query.Select, node, true, _getTableName);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.Except(
                                                                           Queryable.Empty <T>(), new Expression <Func <T, object> >[] { })))
                {
                    HandleSetOperation(query.Select, node, false, _getTableName);
                }
                else if (node.MatchesMethodSignature <IQueryable <T> >(x => x.SyncWith(Queryable.Empty <T>(), y => y,
                                                                                       SyncFields.Exclude, new Expression <Func <T, object> >[] { })))
                {
                    HandleSync(query, node);
                }
                else
                {
                    throw new QueryOperatorNotSupportedException(node.Method);
                }
            }

            VisitMethodCall(node, query, query, true, true, node.Arguments.Skip(1).ToArray());
        }