public override void SetUp ()
    {
      base.SetUp ();

      var selector = ExpressionHelper.CreateLambdaExpression<int, bool> (i => i > 5);
      _node = new SelectExpressionNode (CreateParseInfo (), selector);
    }
Ejemplo n.º 2
0
        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 void GetResolvedSelector ()
    {
      var selector = ExpressionHelper.CreateLambdaExpression<int, bool> (i => i > 5);
      var node = new SelectExpressionNode (CreateParseInfo (), selector);

      var expectedResult = Expression.MakeBinary (ExpressionType.GreaterThan, SourceReference, Expression.Constant (5));

      var result = node.GetResolvedSelector(ClauseGenerationContext);

      ExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result);
    }
    public void Resolve_ReplacesParameter_WithProjection ()
    {
      var node = new SelectExpressionNode (CreateParseInfo (), ExpressionHelper.CreateLambdaExpression<int, int> (j => j * j));
      var expression = ExpressionHelper.CreateLambdaExpression<int, bool> (i => i > 5);

      var result = node.Resolve (expression.Parameters[0], expression.Body, ClauseGenerationContext);

      var expectedResult = Expression.MakeBinary (
          ExpressionType.GreaterThan,
          Expression.MakeBinary (ExpressionType.Multiply, SourceReference, SourceReference),
          Expression.Constant (5));
      ExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result);
    }
        public GroupByWithResultSelectorExpressionNode(
            MethodCallExpressionParseInfo parseInfo,
            LambdaExpression keySelector,
            LambdaExpression elementSelectorOrResultSelector,
            LambdaExpression resultSelectorOrNull)
        {
            ArgumentUtility.CheckNotNull("keySelector", keySelector);
            ArgumentUtility.CheckNotNull("elementSelectorOrResultSelector", elementSelectorOrResultSelector);

            _selectExpressionNode = new SelectExpressionNode(
                CreateParseInfoWithGroupNode(parseInfo, keySelector, elementSelectorOrResultSelector, resultSelectorOrNull),
                CreateSelectorForSelectNode(keySelector, elementSelectorOrResultSelector, resultSelectorOrNull));
        }
    public GroupByWithResultSelectorExpressionNode (
        MethodCallExpressionParseInfo parseInfo, 
        LambdaExpression keySelector, 
        LambdaExpression elementSelectorOrResultSelector, 
        LambdaExpression resultSelectorOrNull)
    {
      ArgumentUtility.CheckNotNull ("keySelector", keySelector);
      ArgumentUtility.CheckNotNull ("elementSelectorOrResultSelector", elementSelectorOrResultSelector);

      _selectExpressionNode = new SelectExpressionNode (
          CreateParseInfoWithGroupNode (parseInfo, keySelector, elementSelectorOrResultSelector, resultSelectorOrNull),
          CreateSelectorForSelectNode (keySelector, elementSelectorOrResultSelector, resultSelectorOrNull));
    }
    private static MethodCallExpressionParseInfo TransformParseInfo (
        MethodCallExpressionParseInfo parseInfo,
        LambdaExpression optionalPredicate,
        LambdaExpression optionalSelector)
    {
      var source = parseInfo.Source;

      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);
      }

      return new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
    }
        private static MethodCallExpressionParseInfo TransformParseInfo(
            MethodCallExpressionParseInfo parseInfo,
            LambdaExpression optionalPredicate,
            LambdaExpression optionalSelector)
        {
            var source = parseInfo.Source;

            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);
            }

            return(new MethodCallExpressionParseInfo(parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression));
        }
        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;
        }