Override Serializable attribute?

J

jhcorey

I have a class that I'm serializing to xml. To omit some properties
from the xml I use the [System.Xml.Serialization.XmlIgnore] attribute.

Now I'm thinking that sometimes I want to include those properties, so
I'm wondering if it's possible to inherit from the original class
overriding that attribute (or leave the attribute out of the base class
and put it in the inherited class).

(Note that I'm struggling with the ISerializable interface, and would
be happy to leave that out of the conversation).

TIA,
Jim
 
N

Nicholas Paldino [.NET/C# MVP]

Jim,

I am curious, you say you are struggling with the ISerializable
interface, but the XmlIgnore attribute has nothing to do with that interface
(XML serialization and serialization are two separate things).

That being said, I believe that the XmlIgnore attribute is an inherited
attribute. Because of that, you can't shut it off, so to speak.

What you need to do for xml serialization is implement the
IXmlSerializable interface, and you can handle the
serialization/deserialization of your class instances through that interface
(of course, you have to do all the work yourself).

You can do the same thing with serialization, by implementing
ISerializable and the custom serialization constructor.

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