Possible Duplicate:
C# getting its own class name
For Visual Studio, I want to create a class template and use a string field that holds the name of a class itself. Is it possible?
For example:
public class MyClass
{
public string TAG = GetClassName(this);
}
When talking about non-static methods use Object.GetType Method which returns the exact runtime type of the instance (a reference to an instance of the Type Class):
this.GetType().Name
When talking about static methods, use MethodBase Class and its GetCurrentMethod Method :
Type t = MethodBase.GetCurrentMethod().DeclaringType;
//t.Name
However, see this post on SO for more info on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With