dump object

grauzone none at example.net
Mon Mar 30 09:05:57 PDT 2009


Qian Xu wrote:
> 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.

Use a newer compiler version. dmd 1.041 should work. I'm successfully 
using this feature for serialization.

> 
> Best regards
> --Qian


More information about the Digitalmars-d-learn mailing list