vendredi 30 janvier 2015

Getting type of derived class from base class

I have the following situation:



class Base<T>
class Derived : Base<Derived>


I know it is a bad practice that the base class knows who is the child class. I want to implement a Singleton base class, and for this, the base class must know who is the derived class, so please don't comment on this bad practice.


Is there a way to get the derived class type?


Getting the type using reflection is obviously problematic, because reflection is kind of static, and you can't cover the case of multiple derived classes.


EDIT: Maybe I wasn't clear enough. I meant that I want to be able to inherit the base class without specifiying the generic argument. It is a little stupid to pass yourself to the base class






Aucun commentaire:

Enregistrer un commentaire