Having the following class (.Net 3.5):
public class Something
{
public string Text {get; private set;}
private Something()
{
Text = string.Empty;
}
public Something(string text)
{
Text = text;
}
}
This serializes without error but the resulting XML does not include the Text property since it does not have a public setter.
Is there a way (the simpler, the better) to have the XmlSerializer include those properties?
XmlSerializeronly cares about public read/write members. One option is to implementIXmlSerializable, but that is a lot of work. A more practical option (if available and suitable) may be to useDataContractSerializer:This works on both public and private members, but the xml produced is not quite the same, and you can’t specify xml attributes.