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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top