Exemplo n.º 1
0
        public static Expression ReplaceParameters(LambdaExpression @in, IEnumerable <Expression> with)
        {
            Expression        expression = @in.Body;
            List <Expression> list       = Enumerable.ToList <Expression>(with);

            if (Enumerable.Count <Expression>((IEnumerable <Expression>)list) == @in.Parameters.Count)
            {
                expression = Enumerable.Aggregate(Enumerable.Zip((IEnumerable <ParameterExpression>)@in.Parameters, (IEnumerable <Expression>)list, (parameter, replace) =>
                {
                    var local_0 = new
                    {
                        parameter = parameter,
                        replace   = replace
                    };
                    return(local_0);
                }), expression, (current, exp) => LambdaSubstituter.Rewrite(current, exp.parameter, exp.replace));
            }
            else
            {
                foreach (ParameterExpression what in @in.Parameters)
                {
                    ParameterExpression parameter1 = what;
                    using (IEnumerator <Expression> enumerator = Enumerable.Where <Expression>((IEnumerable <Expression>)list, (Func <Expression, bool>)(withParameter => parameter1.Type == withParameter.Type)).GetEnumerator())
                    {
                        if (enumerator.MoveNext())
                        {
                            Expression current = enumerator.Current;
                            expression = LambdaSubstituter.Rewrite(expression, what, current);
                        }
                    }
                }
            }
            return(expression);
        }
Exemplo n.º 2
0
 public static Expression Splice(this LambdaExpression e, params Expression[] newExpr)
 {
     return(LambdaSubstituter.ReplaceParameters(e, newExpr));
 }
Exemplo n.º 3
0
 public static Expression Splice(this LambdaExpression e, IEnumerable <Expression> newExpr)
 {
     return(LambdaSubstituter.ReplaceParameters(e, newExpr));
 }
Exemplo n.º 4
0
 public static Expression ReplaceParameters(LambdaExpression @in, params Expression[] with)
 {
     return(LambdaSubstituter.ReplaceParameters(@in, (IEnumerable <Expression>)with));
 }