Obtaining sub/function name in runtime

  • Thread starter Thread starter yoav.benyosef
  • Start date Start date
Y

yoav.benyosef

Hello,

Is there a way to find during runtime the name of current sub or
function?

TIA
 
Is there a way to find during runtime the name of current sub or
function?

Check out StackTrace and StackFrame classes in System.Diagnostics.
Beware of inlining, however, which may result in fewer stack frames than
you expect. Also, collecting stack frame information isn't the fastest
thing in the world, especially if you ship .PDBs and you want line and
file information too.

-- Barry
 
Great. I create a new object of type System.Diagnostics.StackFrame and
use its .GetMethod.Name.

Performence is not an issue since I use this for error logging only.

Thanks
 
Back
Top