Ejemplo n.º 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));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 4
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 TExt provider type and is
 /// decorated with a custom attribute of type TAtt.
 /// </remarks>
 protected bool MatchProviderType(Type candidate)
 {
     return(MefExtensions.IsDescendentOf(candidate, typeof(TExt)) &&
            candidate.GetTypeInfo().GetCustomAttribute <TAtt>() != null);
 }