How can I make a generic helper method to convert the type used by a Func from one type to another within an Expression
I have a Expression<Func<IEmployee, bool>> and I want to convert it to a
Expression<Func<Employee, bool>>.
The second Type always implements the first Type. A generic solution is what I am trying to achieve.
Edit
I have edited the question to be clearer.
Well, you could create an expression that casts and then forwards its argument to the original expression:
If the provider doesn’t support invocation expressions, you will probably need a much more
sophisticated solution that replaces Parameters in the source expression.
EDIT: Ok, since you say your provider doesn’t like the resulting expression, here’s an example of the alternative. It’s a really rough cut of what a parameter-replacer should look like (I just wrote this now as a sample), but it should work fine for your purposes.
And then use it as: