i would like to get the type of the derived class from a static method of its base class.
How can this be accomplished?
Thanks!
class BaseCla
If I'm not mistaken, the code emitted for BaseClass.Ping() and DerivedClass.Ping() is the same, so making the method static without giving it any arguments won't work. Try passing the type as an argument or through a generic type parameter (on which you can enforce an inheritance constraint).
class BaseClass {
static void Ping() where T : BaseClass {
Type t = typeof(T);
}
}
You would call it like this:
BaseClass.Ping();