Exemplo n.º 1
0
        public bool TryGetTypeDefinitionInfo(int typeDefinitionToken, out string namespaceName, out string typeName, out TypeAttributes attributes)
        {
            if (typeDefinitionToken == 0)
            {
                namespaceName = null;
                typeName      = null;
                attributes    = 0;
                return(false);
            }

            // The typeDef name should be fully qualified
            ITypeDefinition t = _writer.GetTypeDefinition(typeDefinitionToken);

            if (_lastTypeDef == typeDefinitionToken)
            {
                typeName      = _lastTypeDefName;
                namespaceName = _lastTypeDefNamespace;
            }
            else
            {
                int generation = (t is INamedTypeDefinition namedType) ? _writer.Module.GetTypeDefinitionGeneration(namedType) : 0;
                typeName = MetadataWriter.GetMetadataName((INamedTypeReference)t, generation);

                INamespaceTypeDefinition namespaceTypeDef;
                if ((namespaceTypeDef = t.AsNamespaceTypeDefinition(_writer.Context)) != null)
                {
                    namespaceName = namespaceTypeDef.NamespaceName;
                }
                else
                {
                    namespaceName = null;
                }

                _lastTypeDef          = typeDefinitionToken;
                _lastTypeDefName      = typeName;
                _lastTypeDefNamespace = namespaceName;
            }

            attributes = _writer.GetTypeAttributes(t.GetResolvedType(_writer.Context));
            return(true);
        }