/// <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; }
public static int GetPointerSize(TypeInfo typeInfo) { using (TypeAttr attr = typeInfo.GetTypeAttr()) { if (attr.Guid == WellKnownGuids.IID_IUnknown || attr.Guid == WellKnownGuids.IID_IDispatch) { return attr.cbSizeInstance; } if (attr.cImplTypes == 1) { TypeInfo parent = typeInfo.GetRefType(0); return GetPointerSize(parent); } return attr.cbSizeInstance; } }
private static bool IsDerivedFromIIDInternal(TypeInfo typeInfo, Guid iid) { using (TypeAttr attr = typeInfo.GetTypeAttr()) { if (attr.Guid == iid) return true; // If we've seen a IUnknown (note that if the iid is IUnknown, we've tested that already)), // we've recused far enough if (attr.Guid == WellKnownGuids.IID_IUnknown) return false; if (attr.cImplTypes == 1) { TypeInfo parent = typeInfo.GetRefType(0); return IsDerivedFromIIDInternal(parent, iid); } } return false; }