示例#1
0
        internal static bool IsAssignableFromHelper(Type current, Type target)
        {
            if (target == null)
            {
                return(false);
            }
            if (current.Equals(target))
            {
                return(true);
            }
            if (target.IsSubclassOf(current))
            {
                return(true);
            }
            Type[] interfaces = target.GetInterfaces();
            for (int i = 0; i < (int)interfaces.Length; i++)
            {
                if (interfaces[i].Equals(current))
                {
                    return(true);
                }
                if (current.IsAssignableFrom(interfaces[i]))
                {
                    return(true);
                }
            }
            if (target.IsGenericParameter)
            {
                Type[] genericParameterConstraints = target.GetGenericParameterConstraints();
                for (int j = 0; j < (int)genericParameterConstraints.Length; j++)
                {
                    if (MetadataOnlyTypeDef.IsAssignableFromHelper(current, genericParameterConstraints[j]))
                    {
                        return(true);
                    }
                }
            }
            ITypeUniverse typeUniverse = Helpers.Universe(current);

            if (typeUniverse == null || !current.Equals(typeUniverse.GetTypeXFromName("System.Object")))
            {
                return(false);
            }
            if (target.IsPointer || target.IsInterface)
            {
                return(true);
            }
            return(target.IsArray);
        }
示例#2
0
 public override bool IsAssignableFrom(Type c)
 {
     if (c == null)
     {
         return(false);
     }
     if (base.IsPointer && c.IsPointer || base.IsByRef && c.IsByRef)
     {
         Type elementType = c.GetElementType();
         if (this.m_type.IsAssignableFrom(elementType) && !elementType.IsValueType)
         {
             return(true);
         }
     }
     return(MetadataOnlyTypeDef.IsAssignableFromHelper(this, c));
 }
        public override bool IsAssignableFrom(Type c)
        {
            if (c == null)
            {
                return(false);
            }
            if (!c.IsArray || c.GetArrayRank() != 1 || !(c is MetadataOnlyVectorType))
            {
                return(MetadataOnlyTypeDef.IsAssignableFromHelper(this, c));
            }
            Type elementType = c.GetElementType();

            if (elementType.IsValueType)
            {
                return(this.GetElementType().Equals(elementType));
            }
            return(this.GetElementType().IsAssignableFrom(elementType));
        }
示例#4
0
 public override bool IsAssignableFrom(Type c)
 {
     return(MetadataOnlyTypeDef.IsAssignableFromHelper(this, c));
 }