Deserialize Custom Collection Extending NameObjectCollectionBase

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have several custom collections that inherit from
System.Collections.Specialized.NameObjectCollectionBase and I want to
serialize and deserialize with the XMLSerializer object. This works great
but my problem is that when the deserialization occurs, it uses the default
add method to add objects to the collection without adding the keys.

My question is this. Is there any way to use the XMLSerializer object to
deserialize and inform the deserialization process which attribute or element
should be considered the key and have it call a different add method with the
key? Or what approach do I have to take?

Thanks
Mark Overstreet
 
Mark,

In this case, you might have to implement IXmlSerializable on your
class, and handle the serialization yourself, reading the associated keys,
and then adding them properly to your collection with the values.

Hope this helps.
 
Back
Top