forked from ezEngine/ezEngine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreflection.d
40 lines (37 loc) · 860 Bytes
/
reflection.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module reflection;
template ResolveType(T)
{
alias ResolveType = T;
}
void PrintMembers(alias T)()
{
foreach(m; __traits(allMembers, T))
{
static if(!__traits(compiles, typeof(__traits(getMember, T, m))))
{
static if(__traits(compiles, ResolveType!(__traits(getMember, T, m))))
{
alias type = ResolveType!(__traits(getMember, T, m));
static if(is(type == class))
{
static if(type.stringof != "ReflectedModule")
pragma(msg, "class " ~ type.stringof);
}
else static if(is(type == struct))
pragma(msg, "struct " ~ type.stringof);
else
pragma(msg, "unkown " ~ type.stringof);
}
}
}
}
mixin template ReflectModule()
{
class ReflectedModule
{
this()
{
PrintMembers!(__traits(parent, ReflectedModule))();
}
}
}