Closed JaiganeshKumaran closed 6 months ago
Can you provide a source MIDL3 and a desired projection?
Here's an example
attribute GuidAttribute
{
Guid InterfaceId;
}
// should be projected as
struct GuidAttribute
{
winrt::guid InterfaceId;
};
Language projections don't project attributes as structs. Some attributes, like ActivatableAttribute
, don't even have a defined layout. That's why ECMA-335 encodes them as attributes rather than structs.
Just to continue the thought experiment, though... @JaiganeshKumaran can you show a little more, like of how you'd want that to be projected onto a type? Are you imaging something like:
[attributeusage(target_runtimeclass), attributename(kittenpart)]
attribute KittenPartAttribute {
String Name;
Single Cuteness;
}
[kittenpart("ears", 2.1)]
runtimeclass TwitchyEars {
}
[kittenpart("toes", 129.3)]
runtimeclass PinkPads {
}
And then the C++/WinRT projection adds attributes like
struct KittenPartAttribute {
std::wstring_view Name;
float Cuteness;
};
And then you can find it at compile time like:
if constexpr (winrt::get_attribute<PinkPads, KittenPartAttribute>().Name == L"ears") {
}
... so somewhere there's a map of runtimeclass/member/etc -> attribute-list?
I'm looking for more of how you'd use this with reflection, not just the "MIDL3 -> C++" part.
I am going to have a WinRT API for reflexion, so will return a boxed object containing the attribute data.
TypeInfo const typeInfo = ...;
KittenPartAttribute const attribute = typeInfo.Attributes().GetAt(n).as<KittenPartAttribute();
OK, so what you really want is a way to have:
TypeInfo
generated for each runtimeclass or interfaceTypeInfo
contains details about that type (what other than attributes?)TypeInfo
contains the attributes from metadata projected as values (structs, probably)Do you get this "for free" with C#'s projection?
You're welcome to add a switch or flag to produce these for your use case. You could also look into writing your own generator (see the metadata tools that cppwinrt sits on) for now while you refine what you're looking for.
This issue is stale because it has been open 10 days with no activity. Remove stale label or comment or this will be closed in 5 days.
I am writing a reflexion API for WinRT and I want to be able to enable access to attributes as boxed structs. Unfortunately, as C++/WinRT does not project attributes as structures, I cannot really do that.