Accessing UDA of private field

Philippe Sigaud philippe.sigaud at gmail.com
Sun Jan 6 11:59:28 PST 2013


On Sun, Jan 6, 2013 at 7:46 PM, d coder <dlang.coder at gmail.com> wrote:

>
> 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
>> }
>>
>>
>>
>
> Hmm....
>
> This works only when main is in the same file (and therefor module) as Foo.
>
>
Yes, but the OP question was to get the attributes in a generic way. The
interesting part is the mixin, the rest is just scaffolding to print a
result.
If Jacob adopts this solution, he can insert these mixins where he needs
them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130106/b6586356/attachment.html>


More information about the Digitalmars-d mailing list