private PropertyBag AddEnumTypeInfoInternal(ITypeInfo typeInfo) { using (var attrScope = typeInfo.CreateAttrScope()) { if (attrScope.Value.typekind == TYPEKIND.TKIND_ALIAS) { ITypeInfo refTypeInfo; typeInfo.GetRefTypeInfo(unchecked ((int)attrScope.Value.tdescAlias.lpValue.ToInt64()), out refTypeInfo); var node = AddEnumTypeInfoInternal(refTypeInfo); if (node != null) { var locator = typeInfo.GetManagedName(); var segments = locator.Split('.'); if (segments.Length > 0) { var namespaceNode = GetOrCreateNamespaceNode(locator); if (namespaceNode != null) { namespaceNode.SetPropertyNoCheck(segments.Last(), node); return(node); } } } } else if (attrScope.Value.typekind == TYPEKIND.TKIND_ENUM) { var node = GetOrCreateEnumTypeInfoNode(typeInfo); if (node != null) { var count = attrScope.Value.cVars; for (var index = 0; index < count; index++) { using (var varDescScope = typeInfo.CreateVarDescScope(index)) { if (varDescScope.Value.varkind == VARKIND.VAR_CONST) { var name = typeInfo.GetMemberName(varDescScope.Value.memid); node.SetPropertyNoCheck(name, Marshal.GetObjectForNativeVariant(varDescScope.Value.desc.lpvarValue)); } } } return(node); } } } return(null); }
private static IEnumerable <ITypeInfo> GetReferencedEnums(ITypeLib typeLib, ITypeInfo typeInfo, Dictionary <Guid, ITypeInfo> processedTypeInfo) { if (typeInfo == null) { yield break; } var guid = typeInfo.GetOrCreateGuid(); if (processedTypeInfo.ContainsKey(guid)) { yield break; } processedTypeInfo.Add(guid, typeInfo); if (typeInfo.IsEnum()) { yield return(typeInfo); yield break; } if (typeInfo.GetContainingTypeLib().GetGuid() != typeLib.GetGuid()) { yield break; } using (var typeAttrScope = typeInfo.CreateAttrScope()) { for (var funcIndex = 0; funcIndex < typeAttrScope.Value.cFuncs; funcIndex++) { using (var funcDescScope = typeInfo.CreateFuncDescScope(funcIndex)) { foreach (var enumTypeInfo in GetReferencedEnums(typeLib, typeInfo, funcDescScope.Value, processedTypeInfo)) { yield return(enumTypeInfo); } } } for (var varIndex = 0; varIndex < typeAttrScope.Value.cVars; varIndex++) { using (var varDescScope = typeInfo.CreateVarDescScope(varIndex)) { foreach (var enumTypeInfo in GetReferencedEnums(typeLib, typeInfo, varDescScope.Value, processedTypeInfo)) { yield return(enumTypeInfo); } } } for (var implTypeIndex = 0; implTypeIndex < typeAttrScope.Value.cImplTypes; implTypeIndex++) { typeInfo.GetRefTypeOfImplType(implTypeIndex, out var href); typeInfo.GetRefTypeInfo(href, out var refTypeInfo); var refGuid = refTypeInfo.GetGuid(); if ((refGuid == typeof(IDispatch).GUID) || (refGuid == typeof(IDispatchEx).GUID)) { continue; } foreach (var enumTypeInfo in GetReferencedEnums(typeLib, refTypeInfo, processedTypeInfo)) { yield return(enumTypeInfo); } } } }