【问题标题】:Serialize XmlDoc comments along with the data将 XmlDoc 注释与数据一起序列化
【发布时间】:2012-10-29 19:53:55
【问题描述】:

我有一个可序列化的类,我想用它的数据(当然)和它的 XmlDoc cmets 序列化它。有谁知道现有的图书馆可以完成这项工作,或者至少是其中的一部分?

以 Intellisense 的方式阅读 C# 代码的 XmlDoc 是一个很好的起点。

因为例子胜于理论,所以我想要下面的(C#)代码

public class ApplicationOptions : ISerializable
{
    ///<summary>This parameter describes the X property</summary>
    public int WindowPositionX;

    ///<summary>This comment is the same as in the XML-serialized form</summary>
    public int WindowPositionY;
}

映射到下面的序列化 XML 表单

<!--This parameter describes the X property-->
<parameter name="WindowPositionX" Value=12 />

<!--This comment is the same as in the XML-serialized form-->
<parameter name="WindowPositionY" Value=13 />

【问题讨论】:

    标签: c# xml serialization xml-documentation


    【解决方案1】:

    我不知道有什么库可以做到这一点,您可以为该类编写自定义序列化程序并使用自定义序列化程序添加 cmets,如下所示:How to write a comment to an XML file when using the XmlSerializer?

    但是您必须阅读 yourlibraryfile.xml 配套文件才能获取 cmets,cmets 不与应用程序一起编译。

    【讨论】:

    • 我对自己解析 MS XmlDoc 文件的 DOM 不太满意(并在我的项目空间中查找它们)。仍然希望找到一个图书馆来为我做肮脏的工作..
    • 不用解析,可以用Linq to XML查询找到类名和属性msdn.microsoft.com/en-us/library/bb387061.aspx
    猜你喜欢
    • 1970-01-01
    • 2016-06-26
    • 2019-10-14
    • 2016-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多