示例#1
0
        private bool IsSubtype(TypeReference type, TypeReference supposedSubType)
        {
            type            = this.RemoveModifiers(type);
            supposedSubType = this.RemoveModifiers(supposedSubType);
            if (String.op_Equality(supposedSubType.GetFriendlyFullName(null), type.GetFriendlyFullName(null)) || String.op_Equality(type.get_FullName(), "System.Object"))
            {
                return(true);
            }
            if (this.IsArrayAssignable(type, supposedSubType))
            {
                return(true);
            }
            V_0 = supposedSubType.Resolve();
            if (V_0 == null)
            {
                return(true);
            }
            if (type as GenericInstanceType != null)
            {
                type = type.GetElementType();
            }
Label2:
            while (V_0 != null)
            {
                if (TypeNamesComparer.AreEqual(type, V_0))
                {
                    return(true);
                }
                V_1 = V_0.get_Interfaces().GetEnumerator();
                try
                {
                    while (V_1.MoveNext())
                    {
                        V_2 = V_1.get_Current();
                        if (!TypeNamesComparer.AreEqual(type, V_2))
                        {
                            continue;
                        }
                        V_3 = true;
                        goto Label1;
                    }
                    goto Label0;
                }
                finally
                {
                    V_1.Dispose();
                }
Label1:
                return(V_3);
            }
            return(false);

Label0:
            if (V_0.get_BaseType() == null)
            {
                return(false);
            }
            V_0 = V_0.get_BaseType().Resolve();
            goto Label2;
        }
        /// <summary>
        /// Checks if <paramref name="supposedSubType"/> is subtype of <paramref name="type"/>.
        /// </summary>
        /// <param name="type">The supposed parent type.</param>
        /// <param name="supposedSubType">The supposed inheriting type.</param>
        /// <returns>Returns True if <paramref name="supposedSubType"/> is subtype of <paramref name="type"/>.</returns>
        private bool IsSubtype(TypeReference type, TypeReference supposedSubType)
        {
            type            = RemoveModifiers(type);
            supposedSubType = RemoveModifiers(supposedSubType);

            if (supposedSubType.GetFriendlyFullName(null) == type.GetFriendlyFullName(null) || type.FullName == "System.Object")
            {
                ///The types are the same, or the check is if a type inherits Object
                return(true);
            }
            if (IsArrayAssignable(type, supposedSubType))
            {
                return(true);
            }
            TypeDefinition supposedSubTypeDef = supposedSubType.Resolve();

            if (supposedSubTypeDef == null)
            {
                //happens with generics only;
                return(true);
            }
            if (type is GenericInstanceType)
            {
                type = type.GetElementType();
            }
            while (supposedSubTypeDef != null)
            {
                if (TypeNamesComparer.AreEqual(type, supposedSubTypeDef))
                {
                    ///Must be here, since mono fails on resolving types sometimes.
                    return(true);
                }
                foreach (TypeReference @interface in supposedSubTypeDef.Interfaces)
                {
                    if (TypeNamesComparer.AreEqual(type, @interface))
                    {
                        return(true);
                    }
                }

                if (supposedSubTypeDef.BaseType == null)
                {
                    ///We are at the root of the class hierarcy, and no match was made.
                    return(false);
                }
                supposedSubTypeDef = supposedSubTypeDef.BaseType.Resolve();
            }
            return(false);
        }