collectionbase derived class and XmlAttribute

  • Thread starter Thread starter Dirk Reske
  • Start date Start date
D

Dirk Reske

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
 
public class MyCollection:CollectionBase
{
private int version;
public int Version
{
get { return this.version; }
set { this.version = value; }
}

[...]
}

doesn't work to...
 
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
 
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
 
Back
Top