public LetSelectExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression selector)
            : base(Utils.CheckNotNull("parseInfo", parseInfo), Utils.CheckNotNull("selector", selector))
        {
            // Heuristically detect "let" constructs
            // Assume a Select call is a "let" construct if its selector looks like this: <x> => new { <x> = <x>, <y> = ... }
            var selectorBody = selector.Body as NewExpression;
            if (selectorBody != null
                && selectorBody.Arguments.Count == 2
                && selectorBody.Arguments[0] == selector.Parameters[0]
                //&& selectorBody.Constructor.DeclaringType.IsDefined(typeof(CompilerGeneratedAttribute), false)
                && selectorBody.Members != null
                && selectorBody.Members.Count == 2)
            {
                _letConstruction = selectorBody;

                _resolvedAdaptedSelector = new ResolvedExpressionCache<Expression>(this);
                _resolvedLetExpression = new ResolvedExpressionCache<Expression>(this);
            }
            else
            {
                _letConstruction = null;

                _resolvedAdaptedSelector = null;
                _resolvedLetExpression = null;
            }
        }
    public SelectManyExpressionNode (
        MethodCallExpressionParseInfo parseInfo, LambdaExpression collectionSelector, LambdaExpression resultSelector)
        : base (parseInfo)
    {
      ArgumentUtility.CheckNotNull ("collectionSelector", collectionSelector);

      if (collectionSelector.Parameters.Count != 1)
        throw new ArgumentException ("Collection selector must have exactly one parameter.", "collectionSelector");

      CollectionSelector = collectionSelector;

      if (resultSelector != null)
      {
        if (resultSelector.Parameters.Count != 2)
          throw new ArgumentException ("Result selector must have exactly two parameters.", "resultSelector");

        ResultSelector = resultSelector;
      }
      else
      {
        var parameter1 = Expression.Parameter (collectionSelector.Parameters[0].Type, collectionSelector.Parameters[0].Name);
        var itemType = ReflectionUtility.GetItemTypeOfClosedGenericIEnumerable (CollectionSelector.Body.Type, "collectionSelector");
        var parameter2 = Expression.Parameter (itemType, parseInfo.AssociatedIdentifier);
        ResultSelector = Expression.Lambda (parameter2, parameter1, parameter2);
      }

      _cachedCollectionSelector = new ResolvedExpressionCache<Expression> (this);
      _cachedResultSelector = new ResolvedExpressionCache<Expression> (this);
    }
    protected FetchExpressionNodeBase (MethodCallExpressionParseInfo parseInfo, LambdaExpression relatedObjectSelector)
        : base (parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("relatedObjectSelector", relatedObjectSelector);

      var memberExpression = relatedObjectSelector.Body as MemberExpression;
      if (memberExpression == null)
      {
        var message = string.Format (
            "A fetch request must be a simple member access expression; '{0}' is a {1} instead.",
            relatedObjectSelector.Body,
            relatedObjectSelector.Body.GetType ().Name);
        throw new ArgumentException (message, "relatedObjectSelector");
      }

      var owner = StripConverts (memberExpression.Expression);
      if (owner.NodeType != ExpressionType.Parameter)
      {
        var message = string.Format (
            "A fetch request must be a simple member access expression of the kind o => o.Related; '{0}' is too complex.",
            relatedObjectSelector.Body);
        throw new ArgumentException (message, "relatedObjectSelector");
      }

      RelationMember = memberExpression.Member;
    }
    public GroupJoinExpressionNode (
        MethodCallExpressionParseInfo parseInfo, 
        Expression innerSequence,
        LambdaExpression outerKeySelector,
        LambdaExpression innerKeySelector,
        LambdaExpression resultSelector)
        : base(parseInfo)
    {
      ArgumentUtility.CheckNotNull ("innerSequence", innerSequence);
      ArgumentUtility.CheckNotNull ("outerKeySelector", outerKeySelector);
      ArgumentUtility.CheckNotNull ("innerKeySelector", innerKeySelector);
      ArgumentUtility.CheckNotNull ("resultSelector", resultSelector);

      if (outerKeySelector.Parameters.Count != 1)
        throw new ArgumentException ("Outer key selector must have exactly one parameter.", "outerKeySelector");
      if (innerKeySelector.Parameters.Count != 1)
        throw new ArgumentException ("Inner key selector must have exactly one parameter.", "innerKeySelector");
      if (resultSelector.Parameters.Count != 2)
        throw new ArgumentException ("Result selector must have exactly two parameters.", "resultSelector");

      var joinResultSelector = Expression.Lambda (Expression.Constant (null), outerKeySelector.Parameters[0], innerKeySelector.Parameters[0]);
      JoinExpressionNode = new JoinExpressionNode (parseInfo, innerSequence, outerKeySelector, innerKeySelector, joinResultSelector);
      
      ResultSelector = resultSelector;
      _cachedResultSelector = new ResolvedExpressionCache<Expression> (this);
    }
 public UnionExpressionNode (MethodCallExpressionParseInfo parseInfo, Expression source2)
   : base (parseInfo, null, null)
 {
   ArgumentUtility.CheckNotNull ("source2", source2);
   Source2 = source2;
   ItemType = ReflectionUtility.GetItemTypeOfClosedGenericIEnumerable (parseInfo.ParsedExpression.Type, "expression");
 }
    public JoinExpressionNode (
        MethodCallExpressionParseInfo parseInfo,
        Expression innerSequence,
        LambdaExpression outerKeySelector,
        LambdaExpression innerKeySelector,
        LambdaExpression resultSelector)
        : base (parseInfo)
    {
      ArgumentUtility.CheckNotNull ("innerSequence", innerSequence);
      ArgumentUtility.CheckNotNull ("outerKeySelector", outerKeySelector);
      ArgumentUtility.CheckNotNull ("innerKeySelector", innerKeySelector);
      ArgumentUtility.CheckNotNull ("resultSelector", resultSelector);

      if (outerKeySelector.Parameters.Count != 1)
        throw new ArgumentException ("Outer key selector must have exactly one parameter.", "outerKeySelector");
      if (innerKeySelector.Parameters.Count != 1)
        throw new ArgumentException ("Inner key selector must have exactly one parameter.", "innerKeySelector");
      if (resultSelector.Parameters.Count != 2)
        throw new ArgumentException ("Result selector must have exactly two parameters.", "resultSelector");

      InnerSequence = innerSequence;
      OuterKeySelector = outerKeySelector;
      InnerKeySelector = innerKeySelector;
      ResultSelector = resultSelector;

      _cachedOuterKeySelector = new ResolvedExpressionCache<Expression> (this);
      _cachedInnerKeySelector = new ResolvedExpressionCache<Expression> (this);
      _cachedResultSelector = new ResolvedExpressionCache<Expression> (this);
    }
    public AllExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression predicate)
        : base (parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("predicate", predicate);

      Predicate = predicate;
      _cachedPredicate = new ResolvedExpressionCache<Expression> (this);
    }
        public FilterExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression predicate)
            : base(parseInfo)
        {
            if (predicate.Parameters.Count != 1)
                throw new ArgumentException("Predicate must have exactly one parameter.", "predicate");

            Predicate = predicate;
            _cachedPredicate = new ResolvedExpressionCache<Expression>(this);
        }
            public LimitExpressionNode(MethodCallExpressionParseInfo parseInfo,ConstantExpression take, ConstantExpression skip)
                : base(parseInfo)
            {
                Utils.CheckNotNull("keySelector", take);
                Utils.CheckNotNull("keySelector", skip);

                Take = take;
                Skip = skip;
                _cachedSelector = new ResolvedExpressionCache<Expression>(this);
            }
    public SelectExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression selector)
        : base (parseInfo)
    {
      ArgumentUtility.CheckNotNull ("selector", selector);

      if (selector.Parameters.Count != 1)
        throw new ArgumentException ("Selector must have exactly one parameter.", "selector");

      Selector = selector;
      _cachedSelector = new ResolvedExpressionCache<Expression> (this);
    }
    public OrderByDescendingExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression keySelector)
        : base (parseInfo)
    {
      ArgumentUtility.CheckNotNull ("keySelector", keySelector);

      if (keySelector.Parameters.Count != 1)
        throw new ArgumentException ("KeySelector must have exactly one parameter.", "keySelector");

      KeySelector = keySelector;
      _cachedSelector = new ResolvedExpressionCache<Expression> (this);
    }
    public AggregateExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression func)
        : base(parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("func", func);

      if (func.Parameters.Count != 2)
        throw new ArgumentException ("Func must have exactly two parameters.", "func");

      Func = func;
      _cachedFunc = new ResolvedExpressionCache<LambdaExpression> (this);
    }
        public InsertAndReturnExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression withSelector
            , ConstantExpression collection)
            : base(parseInfo)
        {
            var withConstant = withSelector.Body as ConstantExpression;
            if (withConstant == null || withConstant.Value != null)
            {
                WithSelector = withSelector;
                _cachedWithSelector = new ResolvedExpressionCache<Expression>(this);
            }

            Collection = collection;
        }
        public RemoveAndReturnExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression keySelector
            ,ConstantExpression collection)
            : base(parseInfo)
        {
            var keyConstant = keySelector.Body as ConstantExpression;
            if (keyConstant == null || keyConstant.Value != null)
            {
                KeySelector = keySelector;
                _cachedKeySelector = new ResolvedExpressionCache<Expression>(this);
            }

            Collection = collection;
        }
    public IExpressionNode Parse (
        string associatedIdentifier, IExpressionNode source, IEnumerable<Expression> arguments, MethodCallExpression expressionToParse)
    {
      ArgumentUtility.CheckNotNullOrEmpty ("associatedIdentifier", associatedIdentifier);
      ArgumentUtility.CheckNotNull ("source", source);
      ArgumentUtility.CheckNotNull ("expressionToParse", expressionToParse);
      ArgumentUtility.CheckNotNull ("arguments", arguments);

      Type nodeType = GetNodeType (expressionToParse);
      var additionalConstructorParameters = arguments.Select (ProcessArgumentExpression).ToArray();

      var parseInfo = new MethodCallExpressionParseInfo (associatedIdentifier, source, expressionToParse);
      return CreateExpressionNode (nodeType, parseInfo, additionalConstructorParameters);
    }
 public GroupByWithResultSelectorExpressionNode (
     MethodCallExpressionParseInfo parseInfo, 
     LambdaExpression keySelector, 
     LambdaExpression elementSelectorOrResultSelector, 
     LambdaExpression resultSelectorOrNull)
   : base (
       CreateParseInfoWithGroupNode (
           parseInfo,
           ArgumentUtility.CheckNotNull ("keySelector", keySelector),
           ArgumentUtility.CheckNotNull ("elementSelectorOrResultSelector", elementSelectorOrResultSelector),
           resultSelectorOrNull), 
       CreateSelectorForSelectNode (
           keySelector,
           elementSelectorOrResultSelector,
           resultSelectorOrNull))
 {
 }
        public UpsertAndReturnExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression searchSelector
            , LambdaExpression insertSelector, LambdaExpression updateSelector, ConstantExpression type)
            : base(parseInfo)
        {
            Utils.CheckNotNull("searchSelector", searchSelector);
            Utils.CheckNotNull("insertSelector", insertSelector);
            Utils.CheckNotNull("updateSelector", updateSelector);
            Utils.CheckNotNull("type", type);

            SearchSelector = searchSelector;
            InsertSelector = insertSelector;
            UpdateSelector = updateSelector;

            UpdateType = type;

            _cachedSearchSelector = new ResolvedExpressionCache<Expression>(this);
            _cachedInsertSelector = new ResolvedExpressionCache<Expression>(this);
            _cachedUpdateSelector = new ResolvedExpressionCache<Expression>(this);
        }
        public LetLambdaExpressionNode(
        MethodCallExpressionParseInfo parseInfo, LambdaExpression letSelector, LambdaExpression collectionSelector)
            : base(parseInfo)
        {
            Utils.CheckNotNull("collectionSelector", collectionSelector);

            CollectionSelector = collectionSelector;

            LetSelector = letSelector;

            var parameter1 = Expression.Parameter(collectionSelector.Parameters[0].Type, collectionSelector.Parameters[0].Name);
            var itemType = CommonUtility.GetItemTypeOfClosedGenericIEnumerable(CollectionSelector.Body.Type, "collectionSelector");
            var parameter2 = Expression.Parameter(itemType, parseInfo.AssociatedIdentifier);
            ResultSelector = Expression.Lambda(parameter2, parameter1, parameter2);

            _cachedCollectionSelector = new ResolvedExpressionCache<Expression>(this);
            _cachedResultSelector = new ResolvedExpressionCache<Expression>(this);
            _cachedLetSelector = new ResolvedExpressionCache<Expression>(this);
        }
    public GroupByExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression keySelector, LambdaExpression optionalElementSelector)
        : base (parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("keySelector", keySelector);

      if (keySelector.Parameters.Count != 1)
        throw new ArgumentException ("KeySelector must have exactly one parameter.", "keySelector");

      if (optionalElementSelector != null && optionalElementSelector.Parameters.Count != 1)
        throw new ArgumentException ("ElementSelector must have exactly one parameter.", "optionalElementSelector");

      KeySelector = keySelector;
      OptionalElementSelector = optionalElementSelector;

      _cachedKeySelector = new ResolvedExpressionCache<Expression> (this);

      if (optionalElementSelector != null)
        _cachedElementSelector = new ResolvedExpressionCache<Expression> (this);
    }
    protected ResultOperatorExpressionNodeBase (
        MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalPredicate, LambdaExpression optionalSelector)
        : base (parseInfo)
    {
      if (optionalPredicate != null && optionalPredicate.Parameters.Count != 1)
        throw new ArgumentException ("OptionalPredicate must have exactly one parameter.", "optionalPredicate");

      if (optionalSelector != null && optionalSelector.Parameters.Count != 1)
        throw new ArgumentException ("OptionalSelector must have exactly one parameter.", "optionalSelector");

      if (optionalPredicate != null)
        Source = new WhereExpressionNode (parseInfo, optionalPredicate);

      if (optionalSelector != null)
      {
        var newParseInfo = new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, Source, parseInfo.ParsedExpression);
        Source = new SelectExpressionNode (newParseInfo, optionalSelector);
      }

      ParsedExpression = parseInfo.ParsedExpression;
    }
        public UpdateAndReturnExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression withSelector
            , LambdaExpression keySelector,ConstantExpression command)
            : base(parseInfo)
        {
            Utils.CheckNotNull("withSelector", withSelector);

            if (withSelector.Parameters.Count != 1)
                throw new ArgumentException("Selector must have exactly one parameter.", "selector");

            WithSelector = withSelector;
            _cachedWithSelector = new ResolvedExpressionCache<Expression>(this);

            var keyConstant = keySelector.Body as ConstantExpression;
            if (keyConstant ==null || keyConstant.Value != null)
            {
                KeySelector = keySelector;
                _cachedKeySelector = new ResolvedExpressionCache<Expression>(this);
            }

            Command = command;
        }
    public AggregateFromSeedExpressionNode (
        MethodCallExpressionParseInfo parseInfo, 
        Expression seed, 
        LambdaExpression func,
        LambdaExpression optionalResultSelector)
      : base(parseInfo, null, null)
    {
      ArgumentUtility.CheckNotNull ("seed", seed);
      ArgumentUtility.CheckNotNull ("func", func);

      if (func.Parameters.Count != 2)
        throw new ArgumentException ("Func must have exactly two parameters.", "func");

      if (optionalResultSelector != null && optionalResultSelector.Parameters.Count != 1)
        throw new ArgumentException ("Result selector must have exactly one parameter.", "optionalResultSelector");

      Seed = seed;
      Func = func;
      OptionalResultSelector = optionalResultSelector;

      _cachedFunc = new ResolvedExpressionCache<LambdaExpression> (this);
    }
    private static MethodCallExpressionParseInfo CreateParseInfoWithGroupNode (
        MethodCallExpressionParseInfo parseInfo, 
        LambdaExpression keySelector, 
        LambdaExpression elementSelectorOrResultSelector, 
        LambdaExpression resultSelectorOrNull)
    {
      var optionalElementSelector = GetOptionalElementSelector (elementSelectorOrResultSelector, resultSelectorOrNull);

      var sourceItemType = ReflectionUtility.GetItemTypeOfClosedGenericIEnumerable (
          parseInfo.ParsedExpression.Arguments[0].Type, 
          "parseInfo.ParsedExpression.Arguments[0].Type");

      MethodCallExpression simulatedGroupByCallWithoutResultSelector;
      if (optionalElementSelector == null)
      {
        simulatedGroupByCallWithoutResultSelector = Expression.Call (
            typeof (Enumerable),
            "GroupBy",
            new[] { sourceItemType, keySelector.Body.Type },
            parseInfo.ParsedExpression.Arguments[0],
            keySelector);
      }
      else
      {
        simulatedGroupByCallWithoutResultSelector = Expression.Call (
            typeof (Enumerable),
            "GroupBy",
            new[] { sourceItemType, keySelector.Body.Type, optionalElementSelector.Body.Type },
            parseInfo.ParsedExpression.Arguments[0],
            keySelector,
            optionalElementSelector);
      }

      var simulatedParseInfo = new MethodCallExpressionParseInfo(parseInfo.AssociatedIdentifier, parseInfo.Source, simulatedGroupByCallWithoutResultSelector);
      var groupBySourceNode = new GroupByExpressionNode (simulatedParseInfo, keySelector, optionalElementSelector);
      return new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, groupBySourceNode, parseInfo.ParsedExpression);
    }
 public LongCountExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalPredicate)
     : base (parseInfo, optionalPredicate, null)
 {
 }
 public FetchOneExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression relatedObjectSelector)
     : base (parseInfo, ArgumentUtility.CheckNotNull ("relatedObjectSelector", relatedObjectSelector))
 {
 }
 public DefaultIfEmptyExpressionNode (MethodCallExpressionParseInfo parseInfo, Expression optionalDefaultValue)
     : base(parseInfo, null, null)
 {
   OptionalDefaultValue = optionalDefaultValue;
 }
Пример #27
0
 public MaxExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalSelector)
     : base(parseInfo, null, optionalSelector)
 {
 }
Пример #28
0
 public MaxExpressionNode (MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalSelector)
     : base (parseInfo, null, optionalSelector)
 {
 }
 public CastExpressionNode (MethodCallExpressionParseInfo parseInfo)
     : base (parseInfo, null, null)
 {
   if (!parseInfo.ParsedExpression.Method.IsGenericMethod || parseInfo.ParsedExpression.Method.GetGenericArguments ().Length != 1)
     throw new ArgumentException ("The parsed method must have exactly one generic argument.", "parseInfo");
 }
 protected ThenFetchExpressionNodeBase (MethodCallExpressionParseInfo parseInfo, LambdaExpression relatedObjectSelector)
     : base(parseInfo, relatedObjectSelector)
 {
 }
 public GroupByExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression selector)
     : base(Utils.CheckNotNull("parseInfo", parseInfo), Utils.CheckNotNull("selector", selector))
 {
     intoIdentifier = parseInfo.AssociatedIdentifier;
     _resolvedAdaptedSelector = new ResolvedExpressionCache<Expression>(this);
 }
 public ReverseExpressionNode(MethodCallExpressionParseInfo parseInfo)
     : base(parseInfo, null, null)
 {
 }
Пример #33
0
 public LastExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalPredicate)
     : base(parseInfo, optionalPredicate, null)
 {
 }
Пример #34
0
 public AverageExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalPredicate)
     : base(parseInfo, null, optionalPredicate)
 {
 }
Пример #35
0
 public TakeExpressionNode(MethodCallExpressionParseInfo parseInfo, Expression count)
     : base(parseInfo, null, null)
 {
     Count = count;
 }