Use IXmlSerializable interface to de-/serialize only some props.
[http://msdn2.microsoft.com/en-us/library/system.xml.serialization.ixmlserializab
le.aspx]
Regards,
Alex
http://devkids.blogspot.com
> I have a class derived from UserControl.
> I need to serialize an object of this class, but only some properties
[quoted text clipped - 5 lines]
> Thank you very much,
> Chris
Thank you, Alex! I've been trying to make it work, but there's a twist
in my situation which I haven't added yet:
My UserControl-derived class is called Basic, and I have some classes
derived from Basic. I never directly use Basic, only its child
classes. I need to serialize a List<Basic>, filled with objects of the
child classes, but I don't know in advance what kind of objects are
used. I found examples how this should be done (a simple example, no
IXmlSerializable interface involved). So when I serialize/deserialize,
I use the following constructor for XmlSerializer class:
public XmlSerializer(Type type, Type[] extraTypes);
like this:
XmlSerializer ser = new XmlSerializer(typeof(List<Basic>), new Type[]
{ typeof(BasicChild1), ..., typeof(BasicChildN) } );
In the simple example, I see that there is an xsi:type="ChildClass"
attribute generated by the serializer. I guess serializer uses this
attribute to construct the object of the appropiate type when
deserializing.
Now the problem: How can I make this work with IXmlSerializable's
ReadXml?
I can generate the appropiate attribute in WriteXml with
XmlWriter.WriteAttributeString, but ReadXml should do something with
this attribute, right?
Thank you again for anyone helping me!
Chris
Alex Meleta ?rta:
> Use IXmlSerializable interface to de-/serialize only some props.
> [http://msdn2.microsoft.com/en-us/library/system.xml.serialization.ixmlserializab
le.aspx]
[quoted text clipped - 12 lines]
> > Thank you very much,
> > Chris