Reputation: 1
I have method that accepts LambdaExpression as a parametar
public void SomeMethod(Expression<Func<SomeObject, bool>> predicate)
{ }
inside this method I would like to extract the members and the arguments values from the expression Body. Is this possible and how can be achieved?
Method can be invoked like this:
SomeMethod(t=> t.Id == 3 && t.Name=="Name");
or
SomeMethod(t=> t.Id.Equals(3));
or
SomeMethod(t=> t.Id > 3 || t.Id = 1);
etc. You get the point.
Upvotes: 0
Views: 1402
Reputation: 1297
The solution you are looking for is called Expression Tree Visitor. By using it you can go though lambda expression members and arguments.
Also this walkthrough may be useful, it contains code for lambda expression partial evaluator in case arguments in lambda expression is not a constants
Upvotes: 2