digitalmars.D.learn - Public visible entities published by a module
- Cecil Ward (7/7) Jul 07 2023 A bit of a weird question, and I’m not sure how to word it. Say I
- Anonymouse (24/31) Jul 07 2023 I did this. It's super ugly and even has `__traits(compiles)` in
- Cecil Ward (2/30) Jul 07 2023 Wow, thankyou so much for your generous reply.
A bit of a weird question, and I’m not sure how to word it. Say I have a module, and I’d like to list / enumerate all the public visible things that the module exports / publishes ‘ makes visible. Is there a way of doing that ? Of getting that kind of listing? I’m wondering about information leaking when things should be encapsulated.
Jul 07 2023
On Friday, 7 July 2023 at 17:46:09 UTC, Cecil Ward wrote:A bit of a weird question, and I’m not sure how to word it. Say I have a module, and I’d like to list / enumerate all the public visible things that the module exports / publishes ‘ makes visible. Is there a way of doing that ? Of getting that kind of listing? I’m wondering about information leaking when things should be encapsulated.I did this. It's super ugly and even has `__traits(compiles)` in there, but as a quick and dirty solution it served well enough. ```d void printPublicMembersOfModule(string module_)() { mixin("import thisModule = " ~ module_ ~ ";"); foreach (symstring; __traits(allMembers, thisModule)) { alias symbol = __traits(getMember, thisModule, symstring); static if ( __traits(compiles, __traits(getVisibility, symbol)) && __traits(getVisibility, symbol) == "public") { pragma(msg, symstring); } } } void main() { printPublicMembersOfModule!"std.stdio"(); } ``` https://run.dlang.io/is/tvNDdp
Jul 07 2023
On Friday, 7 July 2023 at 19:49:06 UTC, Anonymouse wrote:On Friday, 7 July 2023 at 17:46:09 UTC, Cecil Ward wrote:Wow, thankyou so much for your generous reply.[...]I did this. It's super ugly and even has `__traits(compiles)` in there, but as a quick and dirty solution it served well enough. ```d void printPublicMembersOfModule(string module_)() { mixin("import thisModule = " ~ module_ ~ ";"); foreach (symstring; __traits(allMembers, thisModule)) { alias symbol = __traits(getMember, thisModule, symstring); static if ( __traits(compiles, __traits(getVisibility, symbol)) && __traits(getVisibility, symbol) == "public") { pragma(msg, symstring); } } } void main() { printPublicMembersOfModule!"std.stdio"(); } ``` https://run.dlang.io/is/tvNDdp
Jul 07 2023