I might have messed up on a design decision. Instead of using a strongly typed collection of custom objects, I have used a generic List. Essentially, what i have is:
public class AreaFields
{
[XmlArray("Items")]
[XmlArrayItem("Item")]
public List<Fields> Fields { set; get; }
[XmlAttribute]
int id { set; get; }
}
public class Fields
{
[XmlAttribute]
public string Name { set; get; }
}
Throughout the application, I have used List<AreaFields>
Now, I am in need of serializing the list into XML. What I am hoping to get is:
<SomeXMLTag>
<AreaFields id='1000'>
<Items>
<Item Name="Test1" />
<Item Name="Test2" />
</Items>
</AreaFields>
<AreaFields id='1001'>
<Items>
<Item Name="Test1" />
<Item Name="Test2" />
</Items>
</AreaFields>
</SomeXMLTag>
Since I cannot serialize List<> (or can I?), I will have to serialize every item of the list.
Ex: List<AreaFields> list = new List<AreaFields>();
// more code to add to list
list[0].GetRawXML(); //A method i have to serialize