digitalmars.D.learn - Reflecting on a module
- Shammah Chancellor (3/3) Nov 06 2013 How does one reflect on all the classes in a module? I would like to
- Adam D. Ruppe (15/16) Nov 06 2013 __traits(allMembers, your_module)
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 classes.
Nov 06 2013
On Thursday, 7 November 2013 at 01:37:24 UTC, Shammah Chancellor wrote: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