I try to use XDocument
(XML Linq) to save and load classes. For this I have two methods:
static MyClass FromXml(XElement data); //calls 0-parameter constructor inside
public XElement ToXml();
A constructor like this
public MyClass(XElement data)
{
this = MyClass.FromXml(data);
}
does not work (says this is read only).
Can this be done somehow (without creating copying each field manually from the returned value)?
Or is the very idea wrong?
Moving the code from FromXml
to constructor should work, but then saving and loading would be in two places or constructors would not be all in one place...