I met an odd requirement:
There is a api list, and I have to write an example for each api, and the example must be present to user, so it reminded me "Expression tree", method can be stored and executed.
But the problem is, the method will be compiled...
When I debug the expression, I got the IL code.
What I need is:
Func<HttpResponseMessage> func = () =>
{
// do something and call api
// ...
// return the response from api
}
Expression<Func<HttpResponseMessage> expression = SomeMethod(func);
Console.WriteLine(expression.ToString()); // get the func body(NOT COMPILED)
expression.Body.Compile().Invoke(); // compile expression and invoke the func.
Here is a solution, but it was based in MONO.
http://evain.net/blog/articles/2009/04/22/converting-delegates-to-expression-trees/