473,503 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4370

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
9359
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
1524
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
2251
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
1665
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
1360
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
830
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
1278
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
809
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
3777
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
1621
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
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.