www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Reflecting on a module

reply Shammah Chancellor <anonymous coward.com> writes:
How does one reflect on all the classes in a module?  I would like to 
read their attributes and generate an enum from attributes on said 
Nov 06 2013
parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 7 November 2013 at 01:37:24 UTC, Shammah Chancellor 
 How does one reflect on all the classes in a module?
__traits(allMembers, your_module) There's two easy ways to get your_module: __traits(parent, some_top_level_symbol0 or mixin("module.name.here"); allMembers gives a list of strings, which are the names of everything. Then you do __traits(getMember, your_module, name) in the loop to get it and see if it is a class. If you need more details, I can write a sample function too. I used this technique in my terminal emulator utility module: https://github.com/adamdruppe/terminal-emulator/blob/master/utility.d check the main function there. Here, I look for functions marked export, but looking for classes and UDAs isn't much different. static if(is(T == class)), __traits(getAttributes), etc instead of getProtection.
Nov 06 2013