public static Expression <Hoisted <TIn, TOut> > Hoist(Expression <Func <TIn, TOut> > expr)
        {
            // rewrite Expression<Func<TIn, TOut>> as Expression<Hoisted<TIn, TOut>>

            var visitor             = new HoistingExpressionVisitor <TIn, TOut>();
            var rewrittenBodyExpr   = visitor.Visit(expr.Body);
            var rewrittenLambdaExpr = Expression.Lambda <Hoisted <TIn, TOut> >(rewrittenBodyExpr, expr.Parameters[0], _hoistedConstantsParamExpr);

            return(rewrittenLambdaExpr);
        }
예제 #2
0
        public static Expression <Hoisted <TIn, TOut> > Hoist(Expression <Func <TIn, TOut> > expr)
        {
            HoistingExpressionVisitor <TIn, TOut> hoistingExpressionVisitor = new HoistingExpressionVisitor <TIn, TOut>();
            Expression body = hoistingExpressionVisitor.Visit(expr.Body);

            return(Expression.Lambda <Hoisted <TIn, TOut> >(body, new ParameterExpression[]
            {
                expr.Parameters[0],
                HoistingExpressionVisitor <TIn, TOut> ._hoistedConstantsParamExpr
            }));
        }