Accessing UDA of private field

Philippe Sigaud philippe.sigaud at gmail.com
Sun Jan 6 09:29:18 PST 2013


> The problem is that to access a UDA attached to a field I need to pass a
> symbol to the __traits(getAttributes). With "tupleof" I can get the name,
> type and value of a field but I cannot get a symbol.
>
> __traits(getMember) can be used to get the symbol but that will only work
> for public fields.
>

You can use a string mixin:

class Foo
{
    int a;
    @(3) private int b;
}

void main()
{
    writeln(mixin("__traits(getAttributes, " ~ Foo.tupleof[1].stringof ~
")")); // -> 3
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130106/7ba63f44/attachment.html>


More information about the Digitalmars-d mailing list