Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2007

Tip: Looking for answers? Try searching our database.

Serializing some properties of a UserControl-derived class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
she_prog - 28 May 2007 20:49 GMT
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
Alex Meleta - 28 May 2007 21:33 GMT
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
she_prog - 30 May 2007 22:15 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.