www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get attributes of type by string name

reply "JS" <js.mdnq gmail.com> writes:
how can I get the UDA's of a type that I only know by name and 
only in a CTFE.

I would like to loop over an array of names passed to a me(I 
don't know their contents beforehand) and get the attributes.

I've tried to use a mixin but I can't get the mixin to work on 
the string name...

e.g., mixin("alias a = __traits(getAttributes, "~type~");");
Aug 01 2013
parent Jacob Carlborg <doob me.com> writes:
On 2013-08-02 03:02, JS wrote:
 how can I get the UDA's of a type that I only know by name and only in a
 CTFE.

 I would like to loop over an array of names passed to a me(I don't know
 their contents beforehand) and get the attributes.

 I've tried to use a mixin but I can't get the mixin to work on the
 string name...

 e.g., mixin("alias a = __traits(getAttributes, "~type~");");
You need to use a typetuple as well: import std.typetuple; enum attribute; attribute struct Foo {} void main () { alias a = TypeTuple!(__traits(getAttributes, mixin("Foo"))); pragma(msg, a); } -- /Jacob Carlborg
Aug 06 2013