Suppose I have a collection in a class that I'd like to have serialized to XML:
[Serializable]
public class DriveReport : IXmlSerializable
{
public int Capacity { get; set; }
public int FreeSpace { get; set; }
public char DriveLetter { get; set; }
//Assume that the appropriate IXMLSerializable methods are here, where
//the output to the writer concatenates the DriveLetter to the Capacity
//and FreeSpace members, creating an element such as <CFreeSpace>...</CFreeSpace>
}
[Serializable]
public class Report
{
[XmlElement]
public List<DriveReport> DriveReports { get; set; }
}
And suppose I want my XML to have the following output:
<CCapacity>...</CCapacity>
<CFreeSpace>...</CFreeSpace>
<DCapacity>...</DCapacity>
<DFreeSpace>...</DFreeSpace>
If I don't inherit from IXmlSerializable, what I end up with is an element wrapped around those properties i.e.
<DriveReport>
<CCapacity>...</CCapacity>
<CFreeSpace>...</CFreeSpace>
</DriveReport>
Is it possible to emit the previous XML without using an IXmlSerializable implementation in the Report class? And to make things perhaps a little easier, I'm only interested in the serialization, not the deserialization.