如何在 C++/WinRT 中获取底层类型的 TypeName?

How to get TypeName of underlying type in in C++/WinRT?

我正在尝试实现 ICustomPropertyProvider::Type() 方法,但是我找不到获取 C++/WinRT 类型的 TypeName 的方法。显然你在 C++/CX 中有 Object::GetTypeT::typeid,但在 C++/WinRT 中没有。

我尝试了以下代码,但这只是一个大胆的猜测,因为这是我能找到的唯一与类型有远程关系的东西。我认为 typeid() 与 XAML 无关,因为它提供的唯一保证是它 returns 的字符串是唯一标识的。

using namespace Windows::Devices::Enumeration;
using namespace Windows::UI::Xaml::Interop;

TypeName name;
name.Name = typeid(DeviceInformation).name();
name.Kind = TypeKind::Metadata;

winrt::xaml_typename<Type>() 函数模板正是您所追求的。