On Wednesday, 26 March 2014 at 14:16:08 UTC, Ary Borenszweig wrote:
I'd like to generate a toString() method for my classes. For example:

Try this:

  override string toString() {
        import std.conv;
        string s;
        s ~= this.classinfo.name ~ "(";
        foreach(idx, val; this.tupleof) {
                if(idx) s ~= ", ";
                s ~= this.tupleof[idx].stringof[5 .. $];
                s ~= " = ";
                s ~= to!string(val);
        }
        s ~= ")";
        return s;
  }

add that method to Foo.

$ ./test58
test58.Foo(x = 1, y = 2)

Reply via email to