dump object
Qian Xu
quian.xu at stud.tu-ilmenau.de
Mon Mar 30 08:48:57 PDT 2009
Hi All,
previously I saw an article about how to dump an object with all properties.
-----------------code-----------------------
void log(T)(T obj) {
static if (is(T == struct) || is(T == class)){
writef("{");
foreach(i,_;obj.tupleof) {
writefln("%s : %s,", obj.tupleof[i].stringof[4..$], obj.tupleof[i]);
}
writefln("}");
}
else {
writefln(obj);
}
}
-----------------code-----------------------
But this function does not work with private attributes of an object.
How to print all public properties of an object?
It would be very useful for debug propose.
Best regards
--Qian
More information about the Digitalmars-d-learn
mailing list