如何在序列化程序生成的xml中插入注释

本文关键字:xml 插入 注释 程序生成 序列化 | 更新日期: 2024-10-18 07:58:09

我有一些类,例如:

Public Class MyClass
  Public Property MyProperty As Integer = 1
End Class

序列化程序(Xml.Serialization.XmlSerializer)创建Xml:

<?xml version="1.0" encoding="utf-8"?>
<MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <MyProperty>1</MyProperty>
</MyClass>

我如何从序列化程序中得到这样的东西:

<?xml version="1.0" encoding="utf-8"?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <!-- Use positive values less than 10 -->
    <MyProperty>1</MyProperty>
 </MyClass>

谢谢!

如何在序列化程序生成的xml中插入注释

尝试利用[XmlComment(Value="Your Comment")]属性