Help with Serialization

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

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