Я извлек уроки из Учебное руководство Python!
Тип имеет свойство BaseType и метод FindInterfaces.
https://msdn.microsoft.com/en-us/library/system.type.aspx
На самом деле, это почти так. иметь Type.GetAllBaseClassesAndInterfaces
,
Вы можете написать такой метод расширения:
public static IEnumerable<Type> GetBaseTypes(this Type type) {
if(type.BaseType == null) return type.GetInterfaces();
return Enumerable.Repeat(type.BaseType, 1)
.Concat(type.GetInterfaces())
.Concat(type.GetInterfaces().SelectMany<Type, Type>(GetBaseTypes))
.Concat(type.BaseType.GetBaseTypes());
}
Используйте этот код:
Func<Type, List<Type>> f = ty =>
{
var tysReturn = new List<Type>();
if (ty.BaseType != null)
{
tysReturn.Add(ty.BaseType);
}
tysReturn.AddRange(ty.GetInterfaces());
return tysReturn;
};
Функция f
принимает тип и возвращает список его базового типа и интерфейсов.
Надеюсь, это поможет.