Setup:
class Item { private int _value; public Item() { _value = 0; } public int Value { get { return _value; } set { _value = value; } } } class ItemCollection : Collection<Item> { private string _name; public ItemCollection() { _name = string.Empty; } public string Name { get {return _name;} set {_name = value;} } }
Now, trying to serialize using the following code snippet:
ItemCollection items = new ItemCollection(); ... XmlSerializer serializer = new XmlSerializer(typeof(ItemCollection)); using (FileStream f = File.Create(fileName)) serializer.Serialize(f, items);
Looking at the resulting XML, I see that the value of ItemCollection.Name does not exist!
I think it might happen that the serializer sees the ItemCollection type as a simple collection, while ignoring any other added properties ...
Has anyone encountered such a problem and found a solution?
Hi,
StΓ©cy
collections generics inheritance c # xml-serialization
StΓ©cy
source share