2

I've seen older posts here on SO, about one year old which would mean that they do not really cover .NET 4 or maybe even 3.5 on this topic. So here goes.

If you with reflection were to fetch parameters for the current method

ParameterInfo[] methodParams = MethodInfo.GetCurrentMethod().GetParameters();

Looping through each parameter will let you fetch the parameter-name however, there is only a "DefaultValue" which I guess is there because of the new Dynamic Parameters in .NET 4.

However, my question is; Is it still not possible to get the method parameter values without digging into the debugger API?

I know that there might be a design flaw if you even need to consider using this.

Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
  • I think, I answered a very similar question not so long ago: http://stackoverflow.com/questions/2062883/is-there-a-way-to-enumerate-passed-method-paramters/2066654#2066654 As you said, not without design flaws, though. – Alexandra Rusina Jan 27 '10 at 19:20

1 Answers1

3

It is not possible to get the current parameter values without using the Profiling API.

MethodInfo objects are per-method, not per-call. There is no way to connect a MethodInfo with a given stack frame.

In addition, in Release builds, the parameter locals can be optimized out, so the values to not necessarily exist.

The DefaultValue property can be non-null in VB parameters, which already supports default values.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964