how can I get a body from function
Func<bool> methodCall = () => output.SendToFile();
if (methodCall())
Console.WriteLine("Success!");
I need to get this output.SendToFile()
as a string
Another example:
string log = "";
public void Foo<T>(Func<T> func)
{
try
{
var t = func();
}
catch (Exception)
{
//here I need to add the body of the lambda
// log += func.body;
}
}
public void Test()
{
var a = 5;
var b = 6;
Foo(() => a > b);
}
Edit: For more information on this topic see: Expression Trees