I give up! I tried to create a reflection library but D's traits are just too screwed up!
Adam D. Ruppe
destructionator at gmail.com
Fri Apr 5 16:00:26 UTC 2019
On Thursday, 4 April 2019 at 02:19:48 UTC, Alex wrote:
> But because there is no `T` for fields we can't do it so easy,
> so we have to construct the name and use string mixins.
You should pass fields as an alias more often than not. It is a
little tricky when you want to read/write it (the alias is not a
value, so you need to pass a pointer or something separately),
but for reflection you want to use the alias.
UDAs do not exist on types per se, since they are tied to symbols.
> mixin(`static foreach(a; __traits(getAttributes,
> `~T.stringof~`.`~name~`))
This shouldn't use mixin at all, and even if you do use mixin, it
shouldn't be using stringof; .stringof is a code smell and should
almost never be used. This bypasses the local symbol. That is
actually the reason why you get a visibility error.
Just use T. more info:
https://stackoverflow.com/questions/32615733/struct-composition-with-mixin-and-templates/32621854#32621854
More information about the Digitalmars-d
mailing list