Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add XML Comment during serialize/deserialize with VB.NET

Tags:

vb.net

I have an XML document that I am deserializing (VB .NET 3.5 Framework), changing some values, and the serializing again. The original document has several XML Comments in it. When I go through all the deserialize/serialize all of the comments are lost. Is there a way to preserve the comments? If not, is there a way to add comments on serialization without having to walk through with the writer and manually add all of the comments back in the appropriate place?

like image 452
jercra Avatar asked Oct 23 '25 20:10

jercra


1 Answers

No, there isn't. If you want to serialize the contents then you will have to use custom serialization (I assume you are referring to implementing the IXmlSerializable interface) and store the comments in the instance of the class and reserialize them when serializing back to XML.

The runtime can't possibly know that the comment is supposed to be serialized and store it for you, so you have to do it yourself.

like image 123
casperOne Avatar answered Oct 26 '25 20:10

casperOne