Chances of D getting proper runtime reflection?
Martin Nowak
dawg at dawgfoto.de
Wed Aug 24 21:30:20 PDT 2011
It is actually already possible to store meta data in classinfos.
---
import std.stdio;
class A {
int a;
float b;
}
mixin template register(T) if(is(T == class)) {
static this() {
T.classinfo.m_offTi = [OffsetTypeInfo(0, typeid(int)),
OffsetTypeInfo(4, typeid(float))];
}
}
mixin register!A;
void main() {
foreach(offTi; A.classinfo.offTi())
writeln(offTi.offset, offTi.ti);
}
---
The compiler doesn't initialize the m_offTi array. But classinfos are in
the initialized data section, at least for me, so you can write to them.
martin
More information about the Digitalmars-d
mailing list