By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,954 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,954 IT Pros & Developers. It's quick & easy.

Serializing some properties of a UserControl-derived class

P: n/a
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

May 28 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Use IXmlSerializable interface to de-/serialize only some props.
[http://msdn2.microsoft.com/en-us/lib...alizable.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

May 28 '07 #2

P: n/a
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/lib...alizable.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
May 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.