Type.BaseTypewill tell you the type from which the current type is inferred. You can recursively call Type.BaseTypeup .Type.IsAbstract true
static class TypeExtensions {
public static Type GetFirstAbstractBaseType(this Type type) {
if (type == null) {
throw new ArgumentNullException("type");
}
Type baseType = type.BaseType;
if (baseType == null || baseType.IsAbstract) {
return baseType;
}
return baseType.GetFirstAbstractBaseType();
}
Using:
Type abstractBase = typeof(Derived).GetFirstAbstractBaseType();
jason source
share