Get Current Method's parameter values as collection with reflection(?)

  • Thread starter Thread starter Angelos Karantzalis
  • Start date Start date
A

Angelos Karantzalis

Hi y'all .. I hope this is an interesting one ...

Within an executing method, I can call MethodBase.GetCurrentMethod() and
retrieve info about the method that's currently running, including parameter
names & data types.

Is there a way to get the parameter v a l u e s as well ??? ( I know ...
this is indeed weird, but .. don't ask :D )


Cheers,
Angel
O:]
 
Hi,

I don't know for sure if you can get it, a good start point may be
StackFrame class, the parameters are stored in the stack so this may be the
start point.

Please if you find the answer post it back here.

Cheers,
 
I'm afraid that after an extensive search on the web, it seems that the only
way to retrieve parameter values at runtime is by using Debugging API's.
Pitty ...


O:(


Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

I don't know for sure if you can get it, a good start point may be
StackFrame class, the parameters are stored in the stack so this may be the
start point.

Please if you find the answer post it back here.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Angelos Karantzalis said:
Hi y'all .. I hope this is an interesting one ...

Within an executing method, I can call MethodBase.GetCurrentMethod() and
retrieve info about the method that's currently running, including
parameter
names & data types.

Is there a way to get the parameter v a l u e s as well ??? ( I know ....
this is indeed weird, but .. don't ask :D )


Cheers,
Angel
O:]
 
Angelos,

No, you can not. You can only reflect on metadata, which is created a
compile time. To that end, you would have to pass the actual values
yourself to whatever method you wish.

Now, one might think that it would be easy to get the values (and
indeed, it might be because you have access to the stack). However, it
wouldn't be a good idea, because there is no way to make anything "const",
which is needed so that you don't modify anything further up on the stack.

Hope this helps.
 
Back
Top