Introspection - how?
HOSOKAWA Kenchi
hskwk at inter7.jp
Tue May 19 08:12:42 PDT 2009
Vincent Wrote:
> Hello, guys!
> I have a question related D's introspection. I try to solve serialization task (implementing JSON protocol)
> and stuck at very start: getting all class' fields with types, names and values. Just test code:
>
> Thread d;
> foreach(mi; d.classinfo.getMembers(null))
> 13: writefln(mi.name);
>
> test.d(13): Error: function object.MemberInfo.name () does not match parameter types ()
> test.d(13): Error: mi.name can only be called on a mutable object, not const(MemberInfo)
>
> I'm confused with such strange error: what is a problem with using MemberInfo? I just try to GET info, not WRITE!
> Anybody have idea how to get info about members? (see task above)
> Thanks.
We face related problem; classinfo mutability.
my post is article_id=90722.
I have noticed that classinfo relates core of D's class system.
http://www.digitalmars.com/d/2.0/phobos/object.html
A pointer to this appears as the first entry in the class's vtbl[].
It seems that this problem must be treated carefully.
More information about the Digitalmars-d
mailing list