Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# reflection current of runtime parameter values

Tags:

c#

reflection

For some debug code I'm writing Trace code I'm trying to output the name of the method using MethodBase.GetCurrentMethod().ToString() but I also wanted to output the current methods parameter names and values. Is this possible?

like image 245
probably at the beach Avatar asked Mar 21 '26 14:03

probably at the beach


1 Answers

You can get the parameter names (and types, modifiers, attributes etc) via MethodBase.GetParameters but you can't get the values that way. You may want to consider using some form of AOP (such as Postsharp) to add logging for parameter values.

like image 116
Jon Skeet Avatar answered Mar 24 '26 04:03

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!