How can I get the values of the parameters of a calling method?

You cannot do it without introspecting the stack yourself (and this is fragile since many optimizations may mean the stack frame is not what you expect, or even that the parameter passed is not in fact what the method signature would suggest (it is perfectly possible for an optimizing JIT compiler to spot that you are only using a sub field of an object/struct and pass that instead).

The ParameterInfo simply tells you the signature of the method as compiled, not the values that were passed.

The only realistic way to achieve this automatically is via code injection (via something like AOP) to create the data and do what you want with it based on analysing the IL.

This is generally not a good idea, if you need to debug something use a debugger, if you need to log something be explicit about what you are logging.

To be clear simple reflective techniques cannot achieve what you desire with full generality

Leave a Comment