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 =3D new XmlSerializer(typeof(List<Basic>), new Type[]
{ typeof(BasicChild1), ..., typeof(BasicChildN) } );
In the simple example, I see that there is an xsi:type=3D"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 =EDrta:
[quoted text, click to view] > Use IXmlSerializable interface to de-/serialize only some props.
> [
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.ixmlse= rializable.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
> > of it, as not all properties are serializable (some of the properties
> > coming from UserControl are like that). When serializing, how
> > could I ignore all the properties coming from the UserControl
> > class? I know there is XmlIgnoreAttribute, but how could I set it
> > to every property of UserControl, as it is not my class?
> > Thank you very much,
> > Chris