コード例 #1
0
        public unsafe static string?GetVariableName(this ITypeInfo typeInfo, uint variableIndex)
        {
            typeInfo.GetVarDesc(variableIndex, out VARDESC * description)
            .ThrowIfFailed($"Failed to get description for variable index: {variableIndex}");

            MemberId id = description->memid;

            typeInfo.ReleaseVarDesc(description);

            return(typeInfo.GetMemberName(id));
        }
コード例 #2
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);
        }
コード例 #3
0
 public static string GetName(this ITypeInfo typeInfo)
 {
     return(typeInfo.GetMemberName(-1));
 }
コード例 #4
0
        public static IPropertyBag GetTypeLibEnums(this ITypeInfo typeInfo)
        {
            var typeLib     = typeInfo.GetContainingTypeLib();
            var typeLibName = typeLib.GetName();

            var rootNode = new PropertyBag(true);

            var typeInfoCount = typeLib.GetTypeInfoCount();

            for (var typeInfoIndex = 0; typeInfoIndex < typeInfoCount; typeInfoIndex++)
            {
                typeLib.GetTypeInfo(typeInfoIndex, out typeInfo);
                var typeInfoName = typeInfo.GetName();

                var typeAttr = typeInfo.GetTypeAttr();
                if (typeAttr.typekind == TYPEKIND.TKIND_ALIAS)
                {
                    ITypeInfo refTypeInfo;
                    typeInfo.GetRefTypeInfo(unchecked ((int)(long)typeAttr.tdescAlias.lpValue), out refTypeInfo);

                    typeInfo = refTypeInfo;
                    typeAttr = typeInfo.GetTypeAttr();
                }

                if (typeAttr.typekind == TYPEKIND.TKIND_ENUM)
                {
                    var varCount = typeAttr.cVars;
                    for (var varIndex = 0; varIndex < varCount; varIndex++)
                    {
                        IntPtr pVarDesc;
                        typeInfo.GetVarDesc(varIndex, out pVarDesc);
                        try
                        {
                            var varDesc = (VARDESC)Marshal.PtrToStructure(pVarDesc, typeof(VARDESC));
                            if (varDesc.varkind == VARKIND.VAR_CONST)
                            {
                                var varName = typeInfo.GetMemberName(varDesc.memid);

                                object typeLibNodeObj;
                                if (!rootNode.TryGetValue(typeLibName, out typeLibNodeObj) || !(typeLibNodeObj is PropertyBag))
                                {
                                    typeLibNodeObj = new PropertyBag(true);
                                    rootNode.SetPropertyNoCheck(typeLibName, typeLibNodeObj);
                                }

                                object typeInfoNodeObj;
                                var    typeLibNode = (PropertyBag)typeLibNodeObj;
                                if (!typeLibNode.TryGetValue(typeInfoName, out typeInfoNodeObj) || !(typeInfoNodeObj is PropertyBag))
                                {
                                    typeInfoNodeObj = new PropertyBag(true);
                                    typeLibNode.SetPropertyNoCheck(typeInfoName, typeInfoNodeObj);
                                }

                                var typeInfoNode = (PropertyBag)typeInfoNodeObj;
                                typeInfoNode.SetPropertyNoCheck(varName, Marshal.GetObjectForNativeVariant(varDesc.desc.lpvarValue));
                            }
                        }
                        finally
                        {
                            typeInfo.ReleaseVarDesc(pVarDesc);
                        }
                    }
                }
            }

            return(rootNode);
        }