Exemple #1
0
        // Stolen from the guts of MEF ConventionBuilder code,
        // implements the default type selection logic of
        //    ConventionBuilder.ForTypesDerivedFrom<T>()
        internal static bool IsDescendentOf(Type type, Type baseType)
        {
            if (type == baseType || type == typeof(object) || type == null)
            {
                return(false);
            }

            TypeInfo typeInfo1 = type.GetTypeInfo();
            TypeInfo typeInfo2 = baseType.GetTypeInfo();

            if (typeInfo1.IsGenericTypeDefinition)
            {
                return(MefExtensions.IsGenericDescendentOf(typeInfo1, typeInfo2));
            }
            return(typeInfo2.IsAssignableFrom(typeInfo1));
        }
Exemple #2
0
 // Stolen from the guts of MEF ConventionBuilder code,
 // supports the default type selection logic of
 //    ConventionBuilder.ForTypesDerivedFrom<T>()
 internal static bool IsGenericDescendentOf(TypeInfo openType, TypeInfo baseType)
 {
     if (openType.BaseType == null)
     {
         return(false);
     }
     if (openType.BaseType == baseType.AsType())
     {
         return(true);
     }
     foreach (Type type in openType.ImplementedInterfaces)
     {
         if (type.IsConstructedGenericType && type.GetGenericTypeDefinition() == baseType.AsType())
         {
             return(true);
         }
     }
     return(MefExtensions.IsGenericDescendentOf(IntrospectionExtensions.GetTypeInfo(openType.BaseType), baseType));
 }