Пример #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));
        }
Пример #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));
 }
Пример #3
0
 /// <summary>
 /// Evaluates whether a candidate type is a provider type.
 /// </summary>
 /// <remarks>
 /// The default implementation simply tests if the candidate type
 /// is a qualified descendent of the TProv provider type.
 /// <para>
 /// Subclasses may add, or replace with, other conditions such as testing
 /// for the presence of a particular class-level custom attribute or
 /// testing for the presence of other features of the class definition
 /// such as a qualifying constructor signature.
 /// </para>
 /// </remarks>
 protected bool MatchProviderType(Type candidate)
 {
     return(MefExtensions.IsDescendentOf(candidate, typeof(TProv)));
 }