Exemple #1
0
        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);
        }
Exemple #2
0
 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;
 }