Reputation: 2428
I wrote a method like this in C#.
MethodBase method = MethodBase.GetCurrentMethod();
string key ="";
for (int i = 0; i < method.GetParameters().Length; i++)
{
key=method.GetParameters().Name;
// need value of parameter here
}
I'm getting parameter names through the above code. My question is: How can I get the values of the parameters which are coming to my method?
Upvotes: 4
Views: 219
Reputation: 1503419
You can't - not without using the debugger API, at least (which is distinctly non-trivial). That information isn't available via reflection. In particular, the MethodBase
object you're fetching is probably going to be the same one on every invocation.
(I don't think the method you've written is quite as you've shown either, and I really hope you're not calling GetParameters
inside a loop like that, but that's a side issue.)
Upvotes: 5