I need to serialize a class called "NodeCollection", which is a list of "Node" objects. "Node" is an abstract class from which I derive "NodeA" and "NodeB". I can successfully serialize the nodes in the collection. However, I am unable to serialize a public property in NodeCollection.
This is what I get:
<NodeCollection>
<ToolNode xsi:type="NodeA" Name="A" />
<ToolNode xsi:type="NodeB" Name="B" />
</NodeCollection>
and this is the desired output:
<NodeCollection CollectionProperty="true">
<ToolNode xsi:type="NodeA" Name="A" />
<ToolNode xsi:type="NodeB" Name="B" />
</NodeCollection>
The classes are defined as follows:
[Serializable]
[XmlRoot("NodeCollection")]
[XmlInclude(typeof(NodeA))]
[XmlInclude(typeof(NodeB))]
public class NodeCollection : List<Node>
{
...etc...
[XmlElement("CollectionProperty")]
public bool CollectionProperty
{
get { return m_CollectionProperty; }
set { m_CollectionProperty = value; }
}
...etc...
}
public abstract class Node
{
[XmlAttribute("Name")]
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
}
Do you know how I can get NodeCollection's public property "CollectionProperty" to show up in the serialization?
Thank you.