mardi 4 mai 2021

How to compute the level of inheritance for two types?

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:

  1. BaseClass is 0 level of inheritance from BaseClass
  2. DClass2 is 2 level of inheritance from BaseClass
  3. DClass3 is 1 level of inheritance from DClass2.




Aucun commentaire:

Enregistrer un commentaire