microsoft/winmd

calling is_enum on an interface typedef throws an exception

Closed this issue · 1 comments

  for (auto const& type : db.TypeDef) {
    std::cout << (type.is_enum() ? "enum " : "class ") << type.TypeName() << std::endl;
...
  }

winmd2markdown.exe!winmd::impl::throw_invalid(const std::string & message) Line 47 C++
winmd2markdown.exe!winmd::reader::table_base::get_value(const unsigned int row, const unsigned int column) Line 43 C++
winmd2markdown.exe!winmd::reader::row_basewinmd::reader::TypeDef::get_string(const unsigned int column) Line 545 C++
winmd2markdown.exe!winmd::reader::TypeDef::TypeNamespace() Line 61 C++
winmd2markdown.exe!winmd::reader::get_type_namespace_and_name(const winmd::reader::coded_index & type) Line 9 C++
winmd2markdown.exe!winmd::reader::get_base_class_namespace_and_name(const winmd::reader::TypeDef & type) Line 25 C++
winmd2markdown.exe!winmd::reader::extends_type(winmd::reader::TypeDef type, std::basic_string_view<char,std::char_traits> typeNamespace, std::basic_string_view<char,std::char_traits> typeName) Line 30 C++
winmd2markdown.exe!winmd::reader::TypeDef::is_enum() Line 119 C++
winmd2markdown.exe!main() Line 56 C++

The is_enum method is not meant to be used on arbitrary TypeDefs. It is only used for signature parsing. You can use the get_category method to determine what a TypeDef represents.

switch (get_category(type))
{
case category::interface_type:
members.interfaces.push_back(type);
continue;
case category::class_type:
if (extends_type(type, "System"sv, "Attribute"sv))
{
members.attributes.push_back(type);
continue;
}
members.classes.push_back(type);
continue;
case category::enum_type:
members.enums.push_back(type);
continue;
case category::struct_type:
if (get_attribute(type, "Windows.Foundation.Metadata"sv, "ApiContractAttribute"sv))
{
members.contracts.push_back(type);
continue;
}
members.structs.push_back(type);
continue;
case category::delegate_type:
members.delegates.push_back(type);
continue;
}