6

From within a method call I need to "jump" three layers up the stack and retrieve the type and value of the parameters passed to that method. Getting the parameter type is easy but I couldn't find a way to get the value passed to a certain method on the stack.

var st = new StackTrace();
var frames = st.GetFrames();
var methodParameters = frame[2].GetMethod().GetParameters;
// get each parameter value

Note: using StackTraceis not mandatory.

Is there a wayto find a value of a parameter passed to a method during runtime?

Dror Helper
  • 30,292
  • 15
  • 80
  • 129
  • I just ran into this and I couldn't find a good way to get values. I would up creating a framework to store the values on the entry point to my application. – rerun Nov 30 '09 at 15:58
  • I could be asking for the impossible - It seems that it's not possible to get the called method's values from the stacktrace. – Dror Helper Nov 30 '09 at 16:32

1 Answers1

6

I do not think there is a method unless you develop your own system for storing the values.

The reflection namespace represents static data about an assembly, and you would need to retrieve values at runtime.

I found PostSharp mentioned in MSDN forums, but I have never tried it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
BlueTrin
  • 9,610
  • 12
  • 49
  • 78