Trying to play with introspection.
trying o, for a given object, to check its property by name.
Experimenting with the function below.
1. it doesn't compile! mi.name() seems to be a problem?
2. match is always null! even though I pass the name of an existing property
and / or field!
trying to learn introspection, I have this simple test method:
===
static void dumpelement(Object o)
{
if (!o)
return;
auto ci = o.classinfo;
foreach(mi ; ci.getMembers(null))
{
writefln(%s . %s, ci.name, mi.name());
}
}
==
However
Lloyd Dupont wrote:
trying to learn introspection, I have this simple test method:
===
static void dumpelement(Object o)
{
if (!o)
return;
auto ci = o.classinfo;
foreach(mi ; ci.getMembers(null))
{
writefln(%s . %s, ci.name, mi.name());
}
}
Interesting... I think I understand...
Thanks! :)
However an other problem arise with getMembers() it always returns null!
Looking at the code it seems (from my beginner's perspective) that
getMembers() rely on the member field (function) xgetMembers which is always
null, as far as I can tell
On 13/06/2011 13:11, Lloyd Dupont wrote:
Interesting... I think I understand...
Thanks! :)
However an other problem arise with getMembers() it always returns null!
Looking at the code it seems (from my beginner's perspective) that
getMembers() rely on the member field (function) xgetMembers
Thanks Robert!
Mm.. can you (per chance!) share some code?
I'm a newbie and compile time reflection is something which eludes me (so
far...)!
Robert Clipsham wrote in message news:it4vp1$1n5q$1...@digitalmars.com...
Anyway of ... making the runtime update xgetMembers?
My understanding
On 13/06/2011 13:56, Lloyd Dupont wrote:
Thanks Robert!
Mm.. can you (per chance!) share some code?
I'm a newbie and compile time reflection is something which eludes me
(so far...)!
See: http://www.digitalmars.com/d/2.0/traits.html
class MyClass
{
void method1(){}
void
Works a treat!
Thanks for your detailed sample! :)
Robert Clipsham wrote in message news:it5395$2028$1...@digitalmars.com...
See: http://www.digitalmars.com/d/2.0/traits.html
class MyClass
{
void method1(){}
void method2(){}
}
import std.stdio;
void main()
{
foreach