This isn't possible with XmlSerializer
or DataContractSerializer
.
Using DataContractSerializer
, you can serialize / deserialize private
and even readonly
fields / properties, however every field / property to serialize needs to be marked with the DataMember
attribute, so it can't be used for arbitrary types, such as KeyValuePair<K,V>
.
Other than doing it by hand using an XML API (such as Linq2Xml, for example) and reflection, you could look at sharpserializer which seems to do exactly what you're trying to accomplish.