Strange coincidence...as 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.BirthDate, John)
sl.Add(Mary.BirthDate, Mary)
sl.Add(Joe.BirthDate, Joe)
Dim formatter As New Soap.SoapFormatter
Dim saveFile As New FileStream
saveFile = File.OpenWrite("C:\ATest.txt")
formatter.Serialize(saveFile, sl)
saveFile.close()
And here is how to read it:
Dim sl As New SortedList
Dim Formatter As New Soap.SoapFormatter
Dim readFile As New FileStream
readFile = File.OpenRead("C:\ATest.txt")
sl = CType(formatter.Deserialize(readFile), SortedList)
Dim aPerson As Person
Dim dt As Date
For Each dt In sl.Keys
aPerson = Ctype(sl.Item(dt), Person)
MessageBox.Show(aPerson.Name, aPerson.BirthDate.ToString)
Next
John