private static string GetTypeName(IMetadataImport importer, int tk) { // Get the base type name var sbBaseName = new StringBuilder(); var token = new MetadataToken(tk); int size; TypeAttributes pdwTypeDefFlags; int ptkExtends; if (token.IsOfType(MetadataTokenType.TypeDef)) { importer.GetTypeDefProps(token, null, 0, out size, out pdwTypeDefFlags, out ptkExtends ); sbBaseName.Capacity = size; importer.GetTypeDefProps(token, sbBaseName, sbBaseName.Capacity, out size, out pdwTypeDefFlags, out ptkExtends ); } else if (token.IsOfType(MetadataTokenType.TypeRef)) { // Some types extend TypeRef 0x02000000 as a special-case // But that token does not exist so we can't get a name for it if (token.Index != 0) { int resolutionScope; importer.GetTypeRefProps(token, out resolutionScope, null, 0, out size ); sbBaseName.Capacity = size; importer.GetTypeRefProps(token, out resolutionScope, sbBaseName, sbBaseName.Capacity, out size ); } } // Note the base type can also be a TypeSpec token, but that only happens // for arrays, generics, that sort of thing. In this case, we'll leave the base // type name stringbuilder empty, and thus know it's not an enum. return(sbBaseName.ToString()); }