Possible to do from StackTrace?

Possible to do from StackTrace?

Old forum URL: forums.lhotka.net/forums/t/2186.aspx


skagen00 posted on Monday, January 22, 2007

I've leveraged the same sort of call as "CanReadProperty", etc do in something else of mine:

MethodBase callingMethod = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod();

What I'd like to do, if possible, is get the parameters that said method was called with.

That is, if I have:

public void MethodA(int myVar) { MethodB(); }

protected void MethodB()

{

// I want to not only get the calling method (via stacktrace) but also get the parameters of method A - that is, I want to get an object collection or array of which there would be one member - the value of myVar. (not the types)

}

I understand it's unorthodox - but I want to do it for some of the same reasons CanReadProperty utilizes it - to save room for error (string literals), etc.

Copyright (c) Marimer LLC