Created
December 17, 2011 13:21
-
-
Save FelicePollano/1490197 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static class PredicateRewriter | |
| { | |
| public static Expression<Predicate<T>> Rewrite<T>(Expression<Predicate<T>> exp | |
| , string newParamName) | |
| { | |
| var param = Expression.Parameter(exp.Parameters[0].Type, newParamName); | |
| var newExpression = new PredicateRewriterVisitor(param).Visit(exp); | |
| return (Expression<Predicate<T>>)newExpression; | |
| } | |
| private class PredicateRewriterVisitor : ExpressionVisitor | |
| { | |
| private readonly ParameterExpression _parameterExpression; | |
| public PredicateRewriterVisitor(ParameterExpression parameterExpression) | |
| { | |
| _parameterExpression = parameterExpression; | |
| } | |
| protected override Expression VisitParameter(ParameterExpression node) | |
| { | |
| return _parameterExpression; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment