使用 VB.NET 在序列化/反序列化期间添加 XML 注释 [英] Add XML Comment during serialize/deserialize with VB.NET

查看:27
本文介绍了使用 VB.NET 在序列化/反序列化期间添加 XML 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在反序列化的 XML 文档(VB .NET 3.5 框架),更改了一些值,然后再次序列化.原始文档中有几个 XML 注释.当我完成所有反序列化/序列化时,所有评论都丢失了.有没有办法保留评论?如果没有,是否有一种方法可以添加关于序列化的评论,而无需与作者一起完成并手动将所有评论添加回适当的位置?

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?

推荐答案

不,没有.如果要序列化内容,则必须使用自定义序列化(我假设您指的是实现 IXmlSerializable 接口)并将注释存储在类的实例中,并在序列化回 XML 时重新序列化它们.

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.

这篇关于使用 VB.NET 在序列化/反序列化期间添加 XML 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆