Help with Serialization

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I am new to Serialization, so please bear with me.

I have a class inherited from a non-serializable class. My goal is to
serialize an instance of it to XML and I am only interested in the
properties of the inherited class, not those of the base class.

Is there a way to select which properties are to be serialized from my class
so that the XML serializer does not bother with the non-serializable base
class?
 
David,

The best that you could do is use the XmlIgnore attribute. However,
this would require you to redefine all of the properties of the base class
(which you don't want).

I think a better solution is to have a separate wrapper object which
takes an instance of your class, and only exposes the properties that are on
derived classes, ignoring the base class properties. The properties would
then just pass along the values from the object you pass to it. This would
prevent you from having to modify your derived class.

Hope this helps.
 
Back
Top