Executing a modified expression
- by Sam
I found this brief demo:
http://msdn.microsoft.com/en-us/library/bb546136.aspx
Which discusses modifying an expression. However the code starts with a Expression<Func<string, bool>> and ends up with a Expression so it's not complete. How do I take that expression and make it typed as Expression<Func<string,bool>> again?
All the examples I have have found on executing an expression all involve dynamically created expressions which is not what this case has. Here the original expression is defined at compile time. And the code I want to write to do this won't know much about the expression, ideally as little as possible. I definately can't see how I would know what "Paramaters" to pass to Expression.LambdaExpression...
In my particular case I want to search for any references to a particular propery of type A and swap them out with a reference to a property of type B then pass the expression to a call to IEnumerable.Where.
ie.
p=>p.Name == "Sam" where P is Foo1 becomes p=>p.FirstName == "Sam" where p is Foo2