Keith Patrick wrote:
If you have the source code, you can tag it with [XmlIgnore]
Right, but that applies to the property.
Here is an example of what I want:
public class Data
{
string stringValue;
public string StringValue
{
set { stringValue = value; }
}
}
//...
XmlSerializer serializer = new XmlSerializer(typeof(Data));
XmlTextReader reader = new XmlTextReader("data.xml");
Data data = (Data)serializer.Deserialize(reader);
// Presume that data.xml is:
<?xml version="1.0" encoding="utf-8"?>
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<StringValue>Peter</StringValue>
</Data>
----
With the above, after deserialization, data.stringValue will NOT contain
the value "Peter".
From what I've seen, the XmlSerializer will serialize/deserialize
properties that have both a getter and setter.
This seems to be a huge weakness to the serialization, as such a
requirement is purely arbitrary.
Anyone have any comments/suggestions/workarounds?