Exemplo n.º 1
0
        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);
                    }
                }
            }
        }