I am trying to serialize IList. So I am using IXmlSerializable for this. The classes are as follows
class SerializeTarget : IXmlSerializable
{
public IList<Target> Targets { get; set; }
public string Name;
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
throw new NotImplementedException();
}
public void ReadXml(System.Xml.XmlReader reader)
{
throw new NotImplementedException();
}
/// <summary>
/// </summary>
/// <param name="writer">
/// The writer.
/// </param>
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteStartElement("SerializeTarget");
writer.WriteElementString("Name", Name);
writer.WriteStartElement("Targets");
foreach (var target in Targets)
{
///??????
}
writer.WriteEndElement();
writer.WriteEndElement();
}
#endregion
}
class Target : IXmlSerializable
{
public String Name { get; set; }
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
throw new NotImplementedException();
}
public void ReadXml(System.Xml.XmlReader reader)
{
throw new NotImplementedException();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteString(Name);
}
#endregion
}
How can I call the serialize of the nested object from SerializeTarget.Serialize?
If you follow @Henk Holterman advice you also want to change the WriteXML on target to be
you can also use instead of WriteXml()
Either way should give you: