コード例 #1
0
ファイル: ConvCommon.cs プロジェクト: dbremner/clrinterop
        /// <summary>
        /// Is this interface explicitly derives from IEnumerable (from mscorlib.tlb)?
        /// </summary>
        /// <param name="lookupPartner">Whether we look at the partner interface</param>
        public static bool ExplicitlyImplementsIEnumerable(TypeInfo typeInfo, TypeAttr typeAttr, bool lookupPartner)
        {
            // Look through each of the implemented/inherited interfaces
            for (int i = 0; i < typeAttr.cImplTypes; ++i)
            {
                TypeInfo interfaceTypeInfo = typeInfo.GetRefType(i);

                using (TypeAttr interfaceTypeAttr = interfaceTypeInfo.GetTypeAttr())
                {
                    if ((typeInfo.GetImplTypeFlags(i) & TypeLibTypes.Interop.IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE) == 0)
                    {
                        if (interfaceTypeAttr.Guid == WellKnownGuids.IID_IEnumerable)
                            return true;
                        if (ExplicitlyImplementsIEnumerable(interfaceTypeInfo, interfaceTypeAttr))
                            return true;
                    }
                }
            }

            if (lookupPartner)
            {
                TypeInfo partnerTypeInfo = typeInfo.GetRefTypeNoComThrow();
                if (partnerTypeInfo != null)
                {
                    using (TypeAttr partnerTypeAttr = partnerTypeInfo.GetTypeAttr())
                    {
                        if (partnerTypeAttr.Guid == WellKnownGuids.IID_IEnumerable)
                            return true;

                        if (ExplicitlyImplementsIEnumerable(partnerTypeInfo, partnerTypeAttr, false))
                            return true;
                    }
                }
            }

            return false;
        }