If I have the following classes...
public class Source
{
public string Name
{
get;
set;
}
}
public class Destination
{
public string Name
{
get;
set;
}
}
...and I have the following code to create an expression....
Expression<Func<Source, bool>> expression = e => e.Name == "Test;
...what I end up with is a lambda expression with a single parameter (e) of type Source. What I am trying to do is convert this expression to have a parameter of type Destination.
I have tried something like...
Expression<Func<Destination, bool>> expression2 = Expression.Lambda<Func<Destination, bool>>(expression.Body, Expression.Parameter(typeof(Destination), "e")));
...but this does not seem to work.
What is the best way to make this conversion. It seems like, from what I recall working with, the inner parts of the expression tree (in this case, the member expression) are bound to a particular type. Would I need to parse through the entire expression tree in order to make the conversion? Is there something simple I am missing?