You need to get through Expression trees. Here is a sample code:
internal static class myExpressionService
{
public static string Get(Expression<Action> expression)
{
MethodCallExpression methodCallExpression = (MethodCallExpression)expression.Body;
var method = methodCallExpression.Method;
var argument = (ConstantExpression) methodCallExpression.Arguments.First();
return string.Format("{0}.{1}({2})", method.DeclaringType.FullName, method.Name, argument.Value);
}
}
It works if called this way: string result = myExpressionService.Get(() => myService.Do(1));
Output: Namespace.IMyService.Do(1)
You can extend / update it to process your script.
source
share