Using reflection to get method name and parameters

Ash picture Ash · Jan 23, 2009 · Viewed 26.8k times · Source

I am trying to workout a way to programatically create a key for Memcached, based on the method name and parameters. So if I have a method,

string GetName(int param1, int param2);

it would return:

string key = "GetName(1,2)";

I know you can get the MethodBase using reflection, but how do I get the parameters values in the string, not the parameter types?

Answer

Jon Skeet picture Jon Skeet · Jan 23, 2009

You can't get method parameter values from reflection. You'd have to use the debugging/profiling API. You can get the parameter names and types, but not the parameters themselves. Sorry...