Strange coincidence...a s a newbie I was trying various things today
and one was serializing both a HashTable and a SortedList. Both can be
serialized to XML via SOAP. In fact, I placed my Person objects (just
a dumb class I created for learning purposes) and was able to
serialize and deserialize the objects. Not sure how I am going to use
it yet but it was cool.
Here is an example of writing:
Dim sl As New SortedList
Dim John As Person
Dim Mary As Person
Dim Joe As Employee ' employee inherits from Person
John.Name = "John"
John.BirthDay = "01/01/2000"
<etc>
sl.Add(John.Bir thDate, John)
sl.Add(Mary.Bir thDate, Mary)
sl.Add(Joe.Birt hDate, Joe)
Dim formatter As New Soap.SoapFormat ter
Dim saveFile As New FileStream
saveFile = File.OpenWrite( "C:\ATest.t xt")
formatter.Seria lize(saveFile, sl)
saveFile.close( )
And here is how to read it:
Dim sl As New SortedList
Dim Formatter As New Soap.SoapFormat ter
Dim readFile As New FileStream
readFile = File.OpenRead(" C:\ATest.txt")
sl = CType(formatter .Deserialize(re adFile), SortedList)
Dim aPerson As Person
Dim dt As Date
For Each dt In sl.Keys
aPerson = Ctype(sl.Item(d t), Person)
MessageBox.Show (aPerson.Name, aPerson.BirthDa te.ToString)
Next
John
On Thu, 24 Mar 2005 00:58:22 -0800, "Michael Rich"
<mr***@michaelr ich.com> wrote:
Can anyone point me to a collection class that has
serializatio n/deserialization with it - preferably in XML.
I know this can't be done with a collection that inherits from
CollectionBase , but I'm hoping someone has another collection class out
there.
Thanks;
Michael