Universel toString
Qian Xu
quian.xu at stud.tu-ilmenau.de
Fri Mar 20 01:44:43 PDT 2009
Hi All,
I want to write an universel toString() method for debugging propose.
However I cannot write in one version. The compiler says error all the time.
Could someone tell me, how to write an universel one?
What I want, is to convert primtive types (int, int*, bool, bool*, etc.) to
string using "tango.text.Convert.to()" and convert object to string by
calling obj.toString.
----------------------- my current version -------------------------
public char[] toS(int* val)
{
if (val is null)
return "NULL";
return to!(char[])(*val);
}
public char[] toS(Object val)
{
if (val is null)
return "NULL";
return val.toString;
}
public char[] toS(char[] val)
{
if (val is null)
return "NULL";
return val;
}
public char[] toS(int val)
{
return to!(char[])(val);
}
public char[] toS(bool val)
{
return to!(char[])(val);
}
----------------------- my current version -------------------------
Best regards
--Qian Xu
More information about the Digitalmars-d-learn
mailing list