Reputation: 5141
for instance something like:
<apple />
will serialize just fine to a class called "apple". however, if I want to call that class "Dragon" it will not serialize (which makes sense). I want to know how to mark up "Dragon" such that when the XmlSerializer sees it, it knows that "Dragon" is the same as
Upvotes: 6
Views: 1639
Reputation: 18965
Assuming Dragon
defines at least a superset of the properties and fields that apple
does then competent_tech's answer is appropriate though I think your question is actually asking about:
[System.Xml.Serialization.XmlType("apple")]
public class Dragon
If Dragon
is not compatible with apple
then you may be better off performing an explicit conversion between the types. Assuming your application knows the definition of both apple
and Dragon
, this can be accomplished by deserializing your apple
stream to an apple
object, mapping the properties to a new Dragon
object, and then serializing your Dragon
object.
Upvotes: 9
Reputation: 44931
You would want to add the System.Xml.Serialization.XmlTypeAttribute to the class.
[System.Xml.Serialization.XmlType("Dragon")]
public class apple
Upvotes: 5