.NET xml 文档 - 继承文档

发布于 2024-07-09 10:38:47 字数 180 浏览 4 评论 0原文

NDoc 有一个 XML 元素 inheritdoc,它允许您从父类(或实现的接口)继承成员的文档。 但是,Visual Studio(即 C# 编译器)不理解此标记,并抱怨文档不存在或不完整。 StyleCop 和其他一些工具也是如此。 有替代方法吗? 如何在不重复 XML 描述的情况下保持文档完整?

NDoc has an XML element inheritdoc which allows you to inherit documentation of a member from the parent class (or an implemented interface). However, Visual Studio (i.e. the C# compiler) does not understand this tag and complains about the documentation not being present or complete. So does StyleCop and some other tools. Is there an alternative approach? How do you go about keeping the docs complete, yet without duplicating the XML descriptions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

为你鎻心 2024-07-16 10:38:47

我有一个更好的答案:FiXml

使用 GhostDoc 克隆注释当然是可行的方法,但它有明显的缺点,例如:

  • 当原始注释被更改时(这经常发生在发展),
    它的克隆不是。
  • 您正在生成大量重复项。 如果您正在使用任何
    源代码分析工具(例如 Team City 中的 Duplicate Finder),它将
    主要查找您的评论。

FiXml简介:它是由C#\Visual Basic .Net生成的XML文档的后处理器。 它作为 MSBuild 任务实现,因此很容易将其集成到任何项目中。 它解决了与用这些语言编写 XML 文档相关的一些恼人的情况:

  • 不支持从基类或接口继承文档。即任何重写成员的文档都应该从头开始编写,尽管通常情况下这很麻烦至少希望继承其中的一部分。
  • 不支持插入常用的文档模板,例如“此类型是单例 - 使用其 属性来获取唯一的它的实例。”,甚至“初始化 类的新实例。”

为了解决上述问题,提供了以下附加 XML 标记:

  • 标记 <
  • see cref="..." copy=" ..." /> 标记中的属性。

这是其网页下载页面(损坏的链接)。

最后,Sandcastle 中有 标签< /em> - 使用它肯定比复制 XML 注释更好,但与 FiXml 相比,它有一些缺点:

  • Sandcastle 生成编译的 HTML 帮助文件 - 它不会修改 .xml 文件
    包含提取的 XML 注释。 但这些文件被许多工具使用,
    包括 Visual Studio .NET 中的 .NET Reflector 和类浏览器 \ IntelliSense。
    因此,如果您只使用 Sandcastle,您将不会在那里看到继承的文档。
  • Sandcastle 的实现功能不太强大。 例如,没有
    <参见...copy="true"/>

请参阅 Sandcastle 的 描述 了解更多详细信息。

I have a better answer: FiXml.

Cloning comments with GhostDoc is certainly working approach, but it has significant disadvantages, e.g.:

  • When the original comment is changed (which frequently happens during development),
    its clone is not.
  • You're producing huge amount of duplicates. If you're using any
    source code analysis tools (e.g. Duplicate Finder in Team City), it will
    find mainly your comments.

Short description of FiXml: it is a post-processor of XML documentation produced by C# \ Visual Basic .Net. It is implemented as MSBuild task, so it's quite easy to integrate it to any project. It addresses few annoying cases related to writing XML documentation in these languages:

  • No support for inheriting the documentation from base class or interface. I.e. a documentation for any overridden member should be written from scratch, although normally it’s quite desirable to inherit at least the part of it.
  • No support for insertion of commonly used documentation templates, such as “This type is singleton - use its <see cref="Instance" /> property to get the only instance of it.”, or even “Initializes a new instance of <CurrentType> class.”

To solve mentioned issues, the following additional XML tags are provided:

  • <inheritdoc />, <inherited /> tags
  • <see cref="..." copy="..." /> attribute in <see/> tag.

Here is its web page and download page (broken links).

Finally, there is <inheritdoc> tag in Sandcastle - it's definitely better to use it than to copy XML comments, but it has few disadvantages in comparison to FiXml:

  • Sandcastle produces compiled HTML help files - it doesn't modify .xml files
    containing extracted XML comments. But these files are used by many tools,
    including .NET Reflector and class browser \ IntelliSense in Visual Studio .NET.
    So if you use just Sandcastle, you won't see inherited documentation there.
  • Sandcastle's implementation is less powerful. E.g. the is no
    <see ... copy="true" />.

See Sandcastle's <inheritdoc> description for further details.

情何以堪。 2024-07-16 10:38:47

一种替代方法是使用 GhostDoc - 一个 Visual Studio 插件,可以自动为您生成注释。 当然,这会重复 XML 描述,这是您试图避免的事情的一部分 - 但至少它会自动为您完成它。

如果您完全忽略正在继承的方法或重写接口方法的文档,会发生什么? 我怀疑这取决于你如何配置 NDoc,但当然在 MSDN 文档中似乎只是自然地继承了文档 - 并且快速检查建议当你不提供时 VS 不会抱怨继承方法的文档。 当然值得一试。

One alternative is to use GhostDoc - an add-in for Visual Studio that automatically generates comments for you. This duplicates the XML description of course, which is part of what you're trying to avoid - but at least it does it automatically for you.

What happens if you just leave off the docs entirely for methods which are being inherited, or overriding interface methods? I suspect it depends on how you've got NDoc configured, but certainly in MSDN documentation seems to just naturally inherit the docs - and a quick check suggests that VS won't whinge when you don't prodive docs for an inherited method. Worth a try, certainly.

爱的那么颓废 2024-07-16 10:38:47

我构建了一个命令行工具来对 XML 文档文件进行后处理,以添加对的支持。 标签。

它对源代码中的 Intellisense 没有帮助,但它允许将修改后的 XML 文档文件包含在 NuGet 包中,因此可以在引用的 NuGet 包中使用 Intellisense。

有关详细信息,请参阅 www.inheritdoc.io(提供免费版本)。

I built a command line tool to post-process the XML documentation files to add support for the <inheritdoc/> tag.

It doesn't help with Intellisense in source code but it does allow the modified XML documentation files to be included in a NuGet package and therefore works with Intellisense in referenced NuGet packages.

See www.inheritdoc.io for details (free version available).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文