Assume that I have the following classes and inheritance:
public class BaseClass{}
public class DClass:BaseClass {}
public class DClass2:DClass {}
public class DClass3:Dclass2 {}
I can check that DClass*
is a derived class of BaseClass
by using the
typeof(BaseClass).IsAssignableFrom(typeof(DClass))
command.
But is there a way to compute the levels of inheritance? Eg:
BaseClass
is 0 level of inheritance fromBaseClass
DClass2
is 2 level of inheritance fromBaseClass
DClass3
is 1 level of inheritance fromDClass2
.
Aucun commentaire:
Enregistrer un commentaire