コード例 #1
0
        private static Expression <TObject> Compose <TObject>(this Expression <TObject> firstExpression,
                                                              Expression <TObject> secondExpression, Func <Expression, Expression, Expression> mergeFunction)
        {
            var map = firstExpression.Parameters
                      .Select((first, i) => new { first, second = secondExpression.Parameters[i] })
                      .ToDictionary(p => p.second, p => p.first);
            var secondExpressionBody = ParameterRebinder.Rebind(map, secondExpression.Body);
            var newExpressionBody    = mergeFunction(firstExpression.Body, secondExpressionBody);

            return(Expression.Lambda <TObject>(newExpressionBody, firstExpression.Parameters));
        }