示例#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);
 }
示例#2
0
 private static bool InheritsGenericDefinitionInternal(Type currentType, Type genericClassDefinition, out Type implementingType)
 {
     if (TypeExtensions.IsGenericType(currentType))
     {
         Type genericTypeDefinition = currentType.GetGenericTypeDefinition();
         if (genericClassDefinition == genericTypeDefinition)
         {
             implementingType = currentType;
             return(true);
         }
     }
     if (!(TypeExtensions.BaseType(currentType) == null))
     {
         return(InheritsGenericDefinitionInternal(TypeExtensions.BaseType(currentType), genericClassDefinition, out implementingType));
     }
     implementingType = null;
     return(false);
 }
示例#3
0
        private static bool IsOverridenGenericMember(MemberInfo memberInfo, BindingFlags bindingAttr)
        {
            switch (TypeExtensions.MemberType(memberInfo))
            {
            case MemberTypes.Field:
            case MemberTypes.Property:
                Type declaringType = memberInfo.DeclaringType;
                if (!TypeExtensions.IsGenericType(declaringType))
                {
                    return(false);
                }
                Type genericTypeDefinition = declaringType.GetGenericTypeDefinition();
                if (genericTypeDefinition == null)
                {
                    return(false);
                }
                MemberInfo[] member = genericTypeDefinition.GetMember(memberInfo.Name, bindingAttr);
                return(member.Length != 0 && GetMemberUnderlyingType(member[0]).IsGenericParameter);

            default:
                throw new ArgumentException("Member must be a field or property.");
            }
        }
示例#4
0
 public static bool IsNullableType(Type t)
 {
     ValidationUtils.ArgumentNotNull(t, "t");
     return(TypeExtensions.IsGenericType(t) && t.GetGenericTypeDefinition() == typeof(Nullable <>));
 }