On 2011-08-25 05:31, Martin Nowak wrote:
Not sure, I get what you mean. Let me try to clarify this: static Serializeable[TypeInfo] infos; void register(T)() { infos[typeid(T)] = new SerializableImpl!T(); } // Serializable binds static reflection to dynamic interface class SerializeableImpl!T : Serializable { string[] allMembers() { array(__traits(allMembers, T)); } Member getMember(string name) { if (mi = findMemberInfo(name)) { auto res = mi.clone(); // found immutable info, now create wrapper res.address = this + mi.offset; // tell the clone where to find return res; } return null; } } // Member binds purely static info to dynamic interface and an actual address class MemberInfo!T : Member { override void setRaw(TypeInfo ti, void* p) { if (ti is typeid(T)) *address = *cast(T*)p; } override void* getRaw(TypeInfo ti) { if (ti is typeid(T)) return address; } T* address; } In object.d there is a lot of this partly implemented. Have a closer look at OffsetTypeInfo and MemberInfo_field. You can definitely get all the information the compiler could provide for RTTI at compile time. If you try hard enough you may even be able to store them at compile time. The only difference remaining is that you could not access it through instance.classinfo but have to use a table lookup. It would be great if there was a way to append data to classinfo at compile time. Like an extra pointer or an array of ubyte that can be set. martin
I have to take a good look at this but I can say right now that currently how "register" is implemented it needs access to instance methods and variables.
-- /Jacob Carlborg