Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current class name at runtime? [duplicate]

I'm trying to get a current class name into a string.

For example:

public class Marker : Mark
{
    string currentclass = ???;
}

public abstract class MiniMarker : Mark
{
}

I'd like to get the string from Marker class so I do not have to put it inside each abstract class I make from it.

I want the string to be MiniMarker, or what ever the abstract class is named.

I tried MethodBase.GetCurrentMethod().DeclaringType, but it did not work.

like image 916
Craig Avatar asked Aug 20 '12 09:08

Craig


2 Answers

   this.GetType().Name

should return a Class name

like image 114
taffarel Avatar answered Oct 07 '22 22:10

taffarel


This should do:

this.GetType().ToString()
like image 43
Oded Avatar answered Oct 07 '22 22:10

Oded