ToString use with serialization vs other uses

  • Thread starter Thread starter news.austin.rr.com
  • Start date Start date
N

news.austin.rr.com

Hi,

Im thinking of using/overriding ToString in my classes to allow me to
display an objects value as a human readable formated string. Using ToString
for this will come in handy with my custom list control. Instead of adding
strings to my list controls arraylist I can add the actuall object then use
the objects overriden ToString method to have the object return the objects
data in the format I wish to display it in by using the objects ToString
override. i.e. (return this.Column1[this.SelectedIndex].ToString();) This
allows me to return the string if the object in the arraylist is a string or
I can return the string from the objects ToString override if the object in
the arraylist is a different type of object.

My question is.... Should I reserve the ToString overrides for serialization
uses. Since the CF doesn't support XML serialization of objects I plan to
write my own code to read and write objects to a file. I could just create
another method like (ToXmlString) for serialization for the objects i plan
to serialize.

So...
Does this sound solid or should I reserve the ToString overrides for
serialization uses?
 
It is all a matter of opinion.

Mine is to add specific methods for serialization. However I would also use
another method for UI representation of an object e.g. DisplayString. I use
ToString for debugging. So my object gives me info on its internals via
ToString rather than a string to be presented to the user or a serialization
string.

Cheers
Daniel
 
Consider implementing IXmlSerializable interface for custom XML
serialization.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Will using this interface require me to use the objects ToString method?
Thanks


"Ilya Tumanov [MS]" said:
Consider implementing IXmlSerializable interface for custom XML
serialization.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "news.austin.rr.com" <[email protected]>
Subject: ToString use with serialization vs other uses
Date: Thu, 14 Apr 2005 12:02:24 -0500
Lines: 25
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: 169.14.28.23
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.compactframework:26997
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi,

Im thinking of using/overriding ToString in my classes to allow me to
display an objects value as a human readable formated string. Using ToString
for this will come in handy with my custom list control. Instead of adding
strings to my list controls arraylist I can add the actuall object then use
the objects overriden ToString method to have the object return the objects
data in the format I wish to display it in by using the objects ToString
override. i.e. (return this.Column1[this.SelectedIndex].ToString();) This
allows me to return the string if the object in the arraylist is a
string
or
I can return the string from the objects ToString override if the object in
the arraylist is a different type of object.

My question is.... Should I reserve the ToString overrides for serialization
uses. Since the CF doesn't support XML serialization of objects I plan to
write my own code to read and write objects to a file. I could just create
another method like (ToXmlString) for serialization for the objects i plan
to serialize.

So...
Does this sound solid or should I reserve the ToString overrides for
serialization uses?
 
No. This interface has special methods to serialize and desterilize object
as XML.
It's a standard way to provide custom serialization to/from XML.
It's implemented by DataSet, for example and would be used by desktop and
CF V2 XML serializers.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "news.austin.rr.com" <[email protected]>
References: <[email protected]>
Subject: Re: ToString use with serialization vs other uses
Date: Thu, 14 Apr 2005 15:47:12 -0500
Lines: 73
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: 169.14.28.23
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
0.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework.compactframework:75566
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Will using this interface require me to use the objects ToString method?
Thanks


"Ilya Tumanov [MS]" said:
Consider implementing IXmlSerializable interface for custom XML
serialization.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "news.austin.rr.com" <[email protected]>
Subject: ToString use with serialization vs other uses
Date: Thu, 14 Apr 2005 12:02:24 -0500
Lines: 25
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: 169.14.28.23
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.compactframework:26997
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi,

Im thinking of using/overriding ToString in my classes to allow me to
display an objects value as a human readable formated string. Using ToString
for this will come in handy with my custom list control. Instead of adding
strings to my list controls arraylist I can add the actuall object
then
use
the objects overriden ToString method to have the object return the objects
data in the format I wish to display it in by using the objects ToString
override. i.e. (return this.Column1[this.SelectedIndex].ToString();) This
allows me to return the string if the object in the arraylist is a
string
or
I can return the string from the objects ToString override if the
object
in
the arraylist is a different type of object.

My question is.... Should I reserve the ToString overrides for serialization
uses. Since the CF doesn't support XML serialization of objects I plan to
write my own code to read and write objects to a file. I could just create
another method like (ToXmlString) for serialization for the objects i plan
to serialize.

So...
Does this sound solid or should I reserve the ToString overrides for
serialization uses?
 
Back
Top