Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET xml docs - inheriting documentation

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?

like image 506
petr k. Avatar asked Nov 22 '08 13:11

petr k.


People also ask

What does Inheritdoc /> mean?

The @inheritdoc tag indicates that a symbol should inherit its documentation from its parent class. Any other tags that you include in the JSDoc comment will be ignored. This tag is provided for compatibility with Closure Compiler.

What is XML comments C#?

C# documentation comments use XML elements to define the structure of the output documentation. One consequence of this feature is that you can add any valid XML in your documentation comments. The C# compiler copies these elements into the output XML file.


1 Answers

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.

like image 127
Alex Yakunin Avatar answered Sep 22 '22 12:09

Alex Yakunin