jeudi 4 avril 2019

Is it possible to find out the types that have been derived from 1 type

So i have a Type type and i need to find out, wheter there are types that derive from my type and what the types are which derive from my type and i cant just check all assemblies. Now the type i get is dynamic and i get a lot of those so i can't just check the assemblies everytime like this. I would use it, but beforehand i need to know wheter or not other classes derive from my type. Similar acticle, but he knew that he had a type that other classes derive from.

List<Type> list = new List<Type>();
foreach (Type type in Assembly.GetAssembly(myType).GetTypes().Where(i => 
      i.IsClass && !i.IsAbstract && i.IsSubclassOf(myType)))
           {
               list.Add(type);
           }





Aucun commentaire:

Enregistrer un commentaire