basically I want to get the values of the parameters of a called method like this:
var x = 1;
var a = 2;
var b = 3;
Do<HomeController>(o => o.Save(x, "Jimmy", a+b+5, Math.Sqrt(81)));
public static void Do<T>(Expression<Action<T>> expression) where T : Controller
{
// get the values 1,Jimmy,10,9 here
}
Well, you’d need to drill into the expression, find the
MethodCallExpression, and then look at the arguments to it. Note that we don’t have the value ofo, so we’ve got to assume that the arguments to the method don’t rely on that. Also we’re still assuming that the lambda expression just relies on it being aMethodCallExpression?EDIT: Okay, here’s an edited version which evaluates the arguments. However, it assumes you’re not really using the lambda expression parameter within the arguments (which is what the
new object[1]is about – it’s providing a null parameter, effectively).