I'm creating an object which will be serialised and verified against an XSD to create an XML file. The problem I'm having is certain nodes in the XML are duplicated but with different names, so far i've got the following:
public class export
{
public info info { get; set; }
public design design { get; set; }
}
public class info
{
public DateTime exportDateTime { get; set; }
public string duration { get; set; }
public planningSoftware planningSoftware { get; set; }
public exporter exporter { get; set; }
}
public class planningSoftware
{
public string name { get; set; }
public string major { get; set; }
public string minor { get; set; }
public string revision { get; set; }
public string build { get; set; }
}
public class exporter
{
public version version { get; set; }
public module module { get; set; }
}
public class version
{
public string name { get; set; }
public string major { get; set; }
public string minor { get; set; }
public string revision { get; set; }
public string build { get; set; }
}
public class module
{
public string name { get; set; }
public string major { get; set; }
public string minor { get; set; }
public string revision { get; set; }
public string build { get; set; }
}
public static void buildXML()
{
var export = new export()
{
info = new info()
{
exportDateTime = DateTime.Today,
duration = 10,
planningSoftware = new planningSoftware()
{
name = "Planning App",
major = "10",
minor = "4",
revision = "6",
build = "225"
},
exporter = new exporter()
{
version = new version()
{
name = "App Test",
major = "10",
minor = "1",
revision = "0",
build = "201"
},
module = new module()
{
name = "App Test Module",
major = "5",
minor = "2",
revision = "1",
build = "220"
}
}
}
};
var s = new XmlSerializer(typeof(export));
using (var f = File.Open("export.xml", FileMode.Create))
{
s.Serialize(f, export);
}
}
My question is, how can i minimise the duplication of fields here? I might normally initialise a seperate object that holds the values but it looks like this will affect the serialisation.
Thanks.