Collection Class Serialization

M

Michael Rich

Can anyone point me to a collection class that has
serialization/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
 
C

Cor Ligthert

Michael,
Can anyone point me to a collection class that has
serialization/deserialization with it - preferably in XML.
This has only one answer. The dataset.

Cor
 
G

Guest

Michael,

Both arraylist and hashtable can be serialized with a binaryformatter. I
think that arraylist can also be serialized as xml.

I'm surprised that collectionbase is not serializable. Are you sure about
that?

Kerry Moorman
 
J

J L

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
 
S

Shane Story

It is serializable and marked as such; however I am having trouble
serializing it using custom serialization because I can't call
mybase.GetObjectData for it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top