MACROS for current function name?

S

Scott McFadden

C++ has some nice macros for obtaining the current function name, current
source file, and current line number (__FUNCTION__, __FILE__, __LINE__).
Does C# have any comparable MACROS?
 
S

Siva M

C# doesn't have macros. But you still can get the info you are looking for
via standard API:

// __FUNCTION__
System.Diagnostics.StackFrame f = new System.Diagnostics.StackFrame (true);
MessageBox.Show (f.GetMethod().Name);

// __LINE__
System.Diagnostics.StackFrame f = new System.Diagnostics.StackFrame (true);
MessageBox.Show (f.GetFileLineNumber().ToString());


// __FILE__
System.Diagnostics.StackFrame f = new System.Diagnostics.StackFrame (true);
MessageBox.Show (f.GetFileName());


C++ has some nice macros for obtaining the current function name, current
source file, and current line number (__FUNCTION__, __FILE__, __LINE__).
Does C# have any comparable MACROS?
 

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

Top