I have classes like this
[DataContract(Namespace = "")]
public class Foo
{
[DataMember(Order = 0)]
Bar bar;
}
[DataContract(Namespace = "")]
public class Bar
{
Baz baz;
[DataMember(Order = 0)]
string TheBaz
{
get { baz.ToString(); }
set { SomeOtherCode(value); }
}
}
I want this to generate XML like this
<Foo>
<Bar>String from baz.ToString()</Bar>
</Foo>
but am getting something more like:
<Foo>
<Bar><TheBaz>String from baz.ToString()</TheBaz></Bar>
</Foo>
is it possible to fix this? This artical says that one of the disadvantages of DataContractSerializer is:
- No control over how the object is serialized outside of setting the name and the order
leading me to wonder is this is not a solvable problem.
I known this can be done with IXmlSerializable
and ReadXml
/WriteXml
because I'm supposed to be removing code that does just that.