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

时间:2016-04-19 21:12:37

标签: c# xml vb.net

我有一些课,例如:

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

Serializer(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>

谢谢!

1 个答案:

答案 0 :(得分:0)

尽量利用 [XmlComment(值=&#34;您的评论&#34;)]属性