Getting All Classes Which Inherit a Given Base Class


I've been wondering how to get a list of all IClass which inherit from a given IClass?
What I'm trying to do is buidling a lookup list for a new Live Template Macro.

My current implementation looks like this:


IClass baseType = TypesUtil.GetClassType(TypeFactory.CreateTypeByCLRName(arguments[0], projectFile.GetPsiModule()));
if (baseType == null) {
  return null;

IList<ILookupItem> items = new List<ILookupItem>();
PsiLanguageType languageType = MacroUtil.GetLanguageType(context);
IList<IType> types = MacroUtil.GetMacroUtil(context).GetExpectedTypes(context); // <- Tried this, but gives me an empty list :(

foreach (IType type in types) {
  if (TypesUtil.IsClassType(type)) {
    IClass classType = TypesUtil.GetClassType(type);
    if ((classType != null) && (classType.IsNestedTypeOf(baseType))) {
      items.Add(new TypeLookupItem(type, MacroUtil.GetLanguageType(context), DefaultElementPointerFactory.Instance));


Thank you in advance.

Please sign in to leave a comment.