private static Type GetAncestorType(Type type, string ancestorTypeName) { if (type.FullName == ancestorTypeName) { return(type); } // Search interfaces. foreach (var @interface in type.GetInterfaces()) { var ancestorType = GetAncestorType(@interface, ancestorTypeName); if (ancestorType != null) { return(ancestorType); } } // Search base type. var baseType = type.BaseType; if (baseType != null) { return(GetAncestorType(baseType, ancestorTypeName)); } return(null); }
private static Type GetAncestorType(Type type, string ancestorTypeName) { if (type.FullName == ancestorTypeName) { return type; } // Search interfaces. foreach (var @interface in type.GetInterfaces()) { var ancestorType = GetAncestorType(@interface, ancestorTypeName); if (ancestorType != null) { return ancestorType; } } // Search base type. var baseType = type.BaseType; if (baseType != null) { return GetAncestorType(baseType, ancestorTypeName); } return null; }