package reflection
sigod via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 22 07:11:58 PDT 2014
In the video "Case Studies In Simplifying Code With Compile-Time
Reflection" [was pointed out][0] that it is possible to reflect
on imported packages.
So, I tried:
reflection.d:
```
import std.stdio;
import test.module1;
import test.module2;
void main() {
foreach (m; __traits(allMembers, mixin(__MODULE__))) {
writeln(m);
}
writeln("--------------");
foreach (m; __traits(allMembers, test)) {
writeln(m);
}
}
```
test/module1.d:
```
module test.module1;
void module_1() {}
```
test/module2.d:
```
module test.module2;
void module_2() {}
```
It produces:
```
$ rdmd reflection.d
object
std
test
main
--------------
object
module_1
```
As you see `module_2` wasn't listed. If I change order of import
declarations `module_2` will be listed instead of `module_1`.
I also tried to create `test/package.d` and publicly import other
modules through it, but it behave in the same way.
So, how to reflect on imported packages?
[0]: http://youtu.be/xpImt14KTdc?t=42m26s
More information about the Digitalmars-d-learn
mailing list