示例#1
0
        public static LambdaExpression ReplaceParameter(Type acceptsType, LambdaExpression expression,
            ParameterExpression newParam)
        {
            var before = expression.Parameters.FirstOrDefault(x => x.Type == acceptsType) ?? expression.Parameters.FirstOrDefault(x => x.Type.CanBeCastTo(acceptsType));

            if (before == null) return expression;

            var rewriter = new ParameterRewriter(before, newParam);
            return rewriter.VisitAndConvert(expression, "Activator");
        }
示例#2
0
        public static LambdaExpression ReplaceParameter(Type acceptsType, LambdaExpression expression,
                                                        ParameterExpression newParam)
        {
            var before = expression.Parameters.FirstOrDefault(x => { return(x.Type.CanBeCastTo(acceptsType)); });

            if (before == null)
            {
                return(expression);
            }

            var rewriter = new ParameterRewriter(before, newParam);

            return(rewriter.VisitAndConvert(expression, "Activator"));
        }