Introspection - how?
Daniel Keep
daniel.keep.lists at gmail.com
Tue May 19 08:15:44 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.
It doesn't matter; getMembers doesn't currently DO anything. Even if
you cast away the const-ness, you'd get no results.
You have to do this at compile-time with a concrete type for now.
-- Daniel
More information about the Digitalmars-d
mailing list