G
Guest
I have the following classes defined (gets/sets removed for brevity):
[Serializable]
public class Warband
{
public Warband()
{
Contents = new Dictionary<string, WarbandContent>();
}
[XmlElement(ElementName = "Name")]
private string _Name;
[XmlElement(ElementName = "Alignment")]
private string _Alignment;
[XmlElement(ElementName = "BuildTotal")]
private ushort _BuildTotal;
[XmlElement(ElementName = "Activations")]
private ushort _Activations;
[XmlElement(ElementName = "Comments")]
private string _Comments;
[XmlArray(ElementName = "Contents")]
private Dictionary<string, WarbandContent> _Contents;
public void Serialize(string FileName)
{
XmlSerializer serializer = new XmlSerializer(typeof(Warband));
TextWriter writer = new StreamWriter(FileName);
serializer.Serialize(writer, this);
writer.Close();
}
}
[Serializable]
class WarbandContent
{
[XmlElement(ElementName = "MiniatureID")]
private string _MiniatureID;
[XmlElement(ElementName = "Quantity")]
private uint _Quantity;
[XmlElement(ElementName = "Cost")]
private uint _Cost;
[XmlElement(ElementName = "IsCommander")]
private bool _IsCommander;
}
When I call the Serialize method of a Warband object, all properties of that
object are written to the Xml, with the exception of the Dictionary property.
Is there a way to get this Dictionary written to the Xml, or should I start
looking for another way to do this?
Gabe
[Serializable]
public class Warband
{
public Warband()
{
Contents = new Dictionary<string, WarbandContent>();
}
[XmlElement(ElementName = "Name")]
private string _Name;
[XmlElement(ElementName = "Alignment")]
private string _Alignment;
[XmlElement(ElementName = "BuildTotal")]
private ushort _BuildTotal;
[XmlElement(ElementName = "Activations")]
private ushort _Activations;
[XmlElement(ElementName = "Comments")]
private string _Comments;
[XmlArray(ElementName = "Contents")]
private Dictionary<string, WarbandContent> _Contents;
public void Serialize(string FileName)
{
XmlSerializer serializer = new XmlSerializer(typeof(Warband));
TextWriter writer = new StreamWriter(FileName);
serializer.Serialize(writer, this);
writer.Close();
}
}
[Serializable]
class WarbandContent
{
[XmlElement(ElementName = "MiniatureID")]
private string _MiniatureID;
[XmlElement(ElementName = "Quantity")]
private uint _Quantity;
[XmlElement(ElementName = "Cost")]
private uint _Cost;
[XmlElement(ElementName = "IsCommander")]
private bool _IsCommander;
}
When I call the Serialize method of a Warband object, all properties of that
object are written to the Xml, with the exception of the Dictionary property.
Is there a way to get this Dictionary written to the Xml, or should I start
looking for another way to do this?
Gabe