Examining a lambda expression at runtime in C#

Posted by Ben Aston on Stack Overflow See other posts from Stack Overflow or by Ben Aston
Published on 2010-05-20T10:42:44Z Indexed on 2010/05/20 10:50 UTC
Read the original article Hit count: 219

Filed under:
|

I have a method Get on a type MyType1 accepting a Func<MyType2, bool> as a parameter.

An example of its use:

mytype1Instance.Get(x => x.Guid == guid));

I would like create a stub implementation of the method Get that examines the incoming lambda expression and determines what the value of guid is. Clearly the lambda could be "anything", but I'm happy for the stub to make an assumption about the lambda, that it is trying to match on the Guid property.

How can I do this? I suspect it involves the use of the built-in Expression type?

© Stack Overflow or respective owner

Related posts about c#

Related posts about lambda-expressions