473,388 Members | 1,346 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,388 software developers and data experts.

collectionbase derived class and XmlAttribute

Hello,

I've created a collection.

public class MyCollection:CollectionBase
{
public int Version;

[...]
}

I want to serialize it...and it works!
but what do I have to do, that the XmlSerializer serializes the Version
property also?

thx

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
5 1778
"Dirk Reske" <_f*******@gmx.net> wrote in message
news:uy**************@TK2MSFTNGP15.phx.gbl...
public class MyCollection:CollectionBase
{
public int Version;

[...]
}

I want to serialize it...and it works!
but what do I have to do, that the XmlSerializer serializes the Version
property also?


IIRC the XmlSerializer doesn't serialize fields, just public properties.
Wrap it.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
Nov 17 '05 #2
public class MyCollection:CollectionBase
{
private int version;
public int Version
{
get { return this.version; }
set { this.version = value; }
}

[...]
}

doesn't work to...

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
Are you marking your class as serializable? Your extension won't inherit the
attribute.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton

"Dirk Reske" <_f*******@gmx.net> wrote in message
news:Of**************@TK2MSFTNGP09.phx.gbl...
public class MyCollection:CollectionBase
{
private int version;
public int Version
{
get { return this.version; }
set { this.version = value; }
}

[...]
}

doesn't work to...

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #4
yes,

here the top of my class:
[Serializable]
public class Contacts:System.Collections.CollectionBase
{
private int version = 0;

[XmlAttribute("Version")]
public int Version
{
get { return this.version; }
set { this.version = value; }
}

[...]
}

but the XmlSerializer doesn't serialize the Version Property

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5
> public class MyCollection:CollectionBase
{
public int Version;

[...]
}

I want to serialize it...and it works!
but what do I have to do, that the XmlSerializer serializes the Version
property also?


The XmlSerializer does *never* serialize properties of collection classes,
just the content is serialized. You have to move the Version propery to
another class, probably the class containing the collection property.

Example (shown as Xml):
<parent>
<items>
<item />
<item />
<item />
</items>
<version>1.0.0.0</version>
</parent>

Mark
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from...
0
by: rein.petersen | last post by:
Hi All, Some of you may have encountered complications when trying to serialize an object derived from CollectionBase (implementing ICollection or IEnumerable). Specifically, the...
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
6
by: DelGator | last post by:
Foundation...Accessing derived class members through a variable of their base class is just a matter of casting the variable to the derived class. How would you access the derived class members...
2
by: Samuel R. Neff | last post by:
What's the advantage of inheriting from CollectionBase as opposed to just implementing IList? It seems that it saves you from having to implement a few properties (Clear, CopyTo, Count,...
0
by: Jay Sauls | last post by:
I've got a simple XML document (from an external source that I can't change) that I'm having trouble deserializing correctly. The document looks like: <?xml version='1.0'?> <quotes...
3
by: myPosts | last post by:
Hi all, I am having class which is derived from collectionbase class. I am adding some string elements to this collection. What i want is to add support of hashing into class which i have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.