コード例 #1
0
        internal override Expression CreateExpression(Expression parameter)
        {
            var leftExpression = _left.CreateExpression(parameter);

            var innerType = leftExpression.Type.GetGenericArguments()[0];

            var enumerableCall = Expression.Call(typeof(Enumerable), AggregateMethodName, new[] { innerType }, leftExpression);

            return(enumerableCall);
        }
コード例 #2
0
        internal override Expression CreateExpression(Expression parameter)
        {
            if (_left.IsMultiValue)
            {
                if (_right.IsMultiValue)
                {
                    // left.SelectMany(x=>right)
                    var left      = _left.CreateExpression(parameter);
                    var innerType = left.Type.GetGenericArguments()[0];

                    var innerParameter = Expression.Parameter(innerType);
                    var right          = _right.CreateExpression(innerParameter);
                    var rightType      = right.Type.GetGenericArguments()[0];

                    var lambda = Expression.Lambda(right, innerParameter);

                    return(Expression.Call(typeof(Enumerable), "SelectMany", new[] { innerType, rightType }, left, lambda));
                }
                else
                {
                    // left.Select(x=>right)
                    var left      = _left.CreateExpression(parameter);
                    var innerType = left.Type.GetGenericArguments()[0];

                    var innerParameter = Expression.Parameter(innerType);
                    var right          = _right.CreateExpression(innerParameter);

                    var lambda = Expression.Lambda(right, innerParameter);

                    return(Expression.Call(typeof(Enumerable), "Select", new[] { innerType, lambda.ReturnType }, left, lambda));
                }
            }
            else
            {
                // left.right
                var left = _left.CreateExpression(parameter);
                //TODO: what happens if left is null?
                return(_right.CreateExpression(left));
            }
        }