Getting current Method and Namespace information

  • Thread starter Thread starter James
  • Start date Start date
J

James

Is there an easy way to get the name of the current
Method, Class, Namespace etc during code execution. I've
been searching the Framework with little luck.
 
Is there an easy way to get the name of the current
Method, Class, Namespace etc during code execution. I've
been searching the Framework with little luck.

MethodBase current = System.Reflection.MethodBase.GetCurrentMethod();
Console.WriteLine( current.Name );
Console.WriteLine( current.DeclaringType.Name );
Console.WriteLine( current.DeclaringType.Namespace );



Mattias
 
Thanks.
I also found (in C#):
class - this.GetType().Name
namespace - this.GetType().FullName
method - System.Reflection.MethodInfo.GetCurrentMethod
().Name

Seems System.Reflection was the key Framework namespace to
use.
 

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