I'm wondering if it's possible to convert body of a method into a string. We are going to run some scripts with algorithms stored in database.
What I mean is, for example, algorithm:
"var x = 4; return x + 5;"
I would like to be able to test this algorithm before and I would like to have the method in a more standard way:
public int GetResult()
{
var x = 4;
return x + 5;
}
My question is, is it possible to write something like GetResult().ToString(); that would return the body of the GetResult() method?
"var x = 4;return x + 5;"
I am aware that probably such method doesn't exist but if I would have to write some extension, I'd like to try it. I just want to know if it's possible and in what way I should go.
Perhaps reading a .cs file and loading content, then somehow selecting my method would work?