472,096 Members | 1,214 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,096 software developers and data experts.

Obtaining sub/function name in runtime

Hello,

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

TIA

May 15 '06 #1
2 936
"yo***********@gmail.com" <yo***********@gmail.com> wrote:
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
May 15 '06 #2
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

May 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.