I have a bunch of xml serialized objects in a database.
But, I refactored and renamed the classes involved, so deserializing from the db is difficult.
I thought that by adding the term [XmlRoot("DB_Class_Name")]
atop the renamed classes would fix the issue, but it doesn't appear to.
Is there a way to fix the issue using lab开发者_JS百科els like [XmlRoot]
, [XmlElement]
etc., without renaming my classes to their old classnames, and without writing a special deserialize function?
Also, are there any good sources on what is happening under the hood when using xmldeserializaiton and labels like [XmlRoot]
?
First of all, [XmlRoot]
etc. aren't labels, they're attributes.
Second, [XmlRoot]
only affects the class when that class is used as the root element of the document. It has no affect when an instance of that class is used as a child or other descendant.
Use [XmlType]
on the class, or [XmlElement]
on a property that is of the type of the class.
精彩评论