I feel like this is probably a duplicate, but I can't find the exact answer I'm looking for. I am implementing IXmlSerializable on an object and want to know if it would be acceptable to use linq-to-xml.
Replace this...
public void WriteXml(XmlWriter writer)
{
writer.WriteElementString("Name", _name);
writer.WriteElementString("X", _x.ToString());
writer.WriteElementString("Y", _y.ToString());
}
with this...
public void WriteXml(XmlWriter writer)
{
XElement element =
new XElement("MyObj",
new XElement("Name", _name),
new Xelement("X", _x),
new Xelement("Y", _y)
);
element.WriteTo(writer);
}
My actual implementation is obviously more complex to the point that I feel the linq-to-xml structure is simpler and more readable. Is the above acceptable?