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.
 
Back
Top