Exemple #1
0
        public static Expression <Func <TResult> > ApplyPartial <T1, TResult>(this Expression <Func <T1, TResult> > expression, Expression expressionValue)
        {
            var parameterToBeReplaced = expression.Parameters[0];
            var visitor = new ReplacementVisitor(parameterToBeReplaced, expressionValue);
            var newBody = visitor.Visit(expression.Body);

            return(Expression.Lambda <Func <TResult> >(newBody, expression.Parameters[1]));
        }
Exemple #2
0
        private static Expression <Func <T2, TResult> > ApplyPartialLeft <T1, T2, TResult>(Expression <Func <T1, T2, TResult> > expression, T1 value)
        {
            var parameterToBeReplaced = expression.Parameters[0];
            var constant = Expression.Constant(value, parameterToBeReplaced.Type);
            var visitor  = new ReplacementVisitor(parameterToBeReplaced, constant);
            var newBody  = visitor.Visit(expression.Body);

            return(Expression.Lambda <Func <T2, TResult> >(newBody, expression.Parameters[1]));
        }