예제 #1
0
 public static Guid GetGuid(this ITypeInfo typeInfo)
 {
     using (var attrScope = typeInfo.CreateAttrScope())
     {
         return(attrScope.Value.guid);
     }
 }
예제 #2
0
 public static TYPEFLAGS GetFlags(this ITypeInfo typeInfo)
 {
     using (var attrScope = typeInfo.CreateAttrScope())
     {
         return(attrScope.Value.wTypeFlags);
     }
 }
예제 #3
0
 public static TYPEKIND GetKind(this ITypeInfo typeInfo)
 {
     using (var attrScope = typeInfo.CreateAttrScope())
     {
         return(attrScope.Value.typekind);
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
        public static bool IsEnum(this ITypeInfo typeInfo)
        {
            using (var attrScope = typeInfo.CreateAttrScope())
            {
                if (attrScope.Value.typekind == TYPEKIND.TKIND_ENUM)
                {
                    return(true);
                }

                if (attrScope.Value.typekind == TYPEKIND.TKIND_ALIAS)
                {
                    typeInfo.GetRefTypeInfo(unchecked ((int)attrScope.Value.tdescAlias.lpValue.ToInt64()), out var refTypeInfo);
                    return(refTypeInfo.IsEnum());
                }

                return(false);
            }
        }
        public static IEnumerable <DispatchMember> GetDispatchMembers(this ITypeInfo typeInfo)
        {
            using (var attrScope = typeInfo.CreateAttrScope())
            {
                var count        = attrScope.Value.cFuncs;
                var isEnumerable = false;

                var names = new string[1];
                for (var index = 0; index < count; index++)
                {
                    using (var funcDescScope = typeInfo.CreateFuncDescScope(index))
                    {
                        if (funcDescScope.Value.memid == SpecialDispIDs.NewEnum)
                        {
                            isEnumerable = true;
                        }

                        if ((funcDescScope.Value.wFuncFlags & (short)FUNCFLAGS.FUNCFLAG_FRESTRICTED) != 0)
                        {
                            continue;
                        }

                        int nameCount;
                        typeInfo.GetNames(funcDescScope.Value.memid, names, 1, out nameCount);
                        if (nameCount > 0)
                        {
                            yield return(new DispatchMember(names[0], funcDescScope.Value.memid, funcDescScope.Value.invkind));
                        }

                        if (isEnumerable)
                        {
                            yield return(new DispatchMember("GetEnumerator", SpecialDispIDs.GetEnumerator, INVOKEKIND.INVOKE_FUNC));
                        }
                    }
                }
            }
        }
예제 #7
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);
                    }
                }
            }
        }