473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Serializing some properties of a UserControl-derived class

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
2 4356

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: james | last post by:
I cannot get my UserControl's browsable properties to show up in the designer properties panel. I have then public virtual bool TestProp { {get return testProp; } set { testProp = value; } } ...
0
by: Peter Verburgh | last post by:
Hello, I'm using PropertyGrid control to show the properties of an control. There are standard properties for each usercontrol like "Cursor, Dock ,...ect" I don't want to show this properties...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
2
by: Daniel Friend | last post by:
Hello, I have added a custom usercontrol programically and all works fine... I would like to change some custom properties that I have set in that usercontrol. Any help would be greatly...
0
by: Daniel Friend | last post by:
Hello, I have added a custom usercontrol programically and all works fine... I would like to change some custom properties that I have set in that usercontrol. Any help would be greatly...
0
by: elziko | last post by:
I have a UserControl inside my project. When I click on the UserControl in the design view I get to also view all its properties in the property grid. I the change the AllowDrop property to True. ...
3
by: Jim Hubbard | last post by:
If I create a usercontrol that is a tab with a webbrowser control on it, by default the new control exposes no properties of the tab or webbrowser control. What is the easiest way to bubble the...
0
by: Charlie | last post by:
For a Windows Form: A Label is added to a UserControl. A public property of type Label is added to the UserControl code to represent the Label. The property, LabelOne, provides a tree view in...
5
by: g6023 | last post by:
Hi All Newbie to C# I am afraid The array of panel dispays OK but I am having problems with accessing the controls within. My panels each have a number of label controls. How do I set, say,...
3
by: segecko | last post by:
Hi I have a created a custom usercontrol which inherites an Excel like usercontrol. In this usercontrol I have a custom property called SpreadTemplate, which is an enum with (at the moment) two...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.