Example #1
0
 public static bool ImplementsGenericDefinition(Type type, Type genericInterfaceDefinition, out Type implementingType)
 {
     ValidationUtils.ArgumentNotNull(type, "type");
     ValidationUtils.ArgumentNotNull(genericInterfaceDefinition, "genericInterfaceDefinition");
     if (!TypeExtensions.IsInterface(genericInterfaceDefinition) || !TypeExtensions.IsGenericTypeDefinition(genericInterfaceDefinition))
     {
         throw new ArgumentNullException(StringUtils.FormatWith("'{0}' is not a generic interface definition.", CultureInfo.InvariantCulture, genericInterfaceDefinition));
     }
     if (TypeExtensions.IsInterface(type) && TypeExtensions.IsGenericType(type))
     {
         Type genericTypeDefinition = type.GetGenericTypeDefinition();
         if (genericInterfaceDefinition == genericTypeDefinition)
         {
             implementingType = type;
             return(true);
         }
     }
     foreach (Type type1 in type.GetInterfaces())
     {
         if (TypeExtensions.IsGenericType(type1))
         {
             Type genericTypeDefinition = type1.GetGenericTypeDefinition();
             if (genericInterfaceDefinition == genericTypeDefinition)
             {
                 implementingType = type1;
                 return(true);
             }
         }
     }
     implementingType = null;
     return(false);
 }
Example #2
0
 public static bool IsInstantiatableType(Type t)
 {
     ValidationUtils.ArgumentNotNull(t, "t");
     return(!TypeExtensions.IsAbstract(t) && !TypeExtensions.IsInterface(t) && (!t.IsArray && !TypeExtensions.IsGenericTypeDefinition(t)) && (!(t == typeof(void)) && HasDefaultConstructor(t)));
 }