[Gtk-sharp-list] Idea: ToString() methods

Miguel de Icaza miguel@ximian.com
19 Aug 2002 15:10:20 -0400


Hello,

> How about trying to stay "compatible" with the output of the classes in
> the System.Drawing namespace?
> 
> On MS.NET:
> 
> Console.WriteLine(new System.Drawing.Point(1,2).ToString());
> Console.WriteLine(new System.Drawing.Rectangle(1,2,3,4).ToString());
> Console.WriteLine(System.Drawing.Color.Blue.ToString());
> Console.WriteLine(System.Drawing.Color.FromArgb(100,100,100).ToString())
> ;
> 
> Prints out this:
> 
> {X=1,Y=2}
> {X=1,Y=2,Width=3,Height=4}
> Color [Blue]
> Color [A=255, R=100, G=100, B=100]

Well, there is a problem here.  ToString() is officially documented in
the Object base class as being just a debugging tool, and not intended
to be used for real use.  A few classes though, use ToString() as their
officially supported method of stringifying themselves (like
StringBuilder.ToString).

So in the above scenario, ToString() looks like debugging, but in the
Gtk# case, we could make it a bit more useful.  For instance, the rgb:
notation from X11 can be copy/pasted in source code or program command
lines, or input fields to specify a color.

I do not feel strongly about this though.

Miguel