views:

1201

answers:

4

Would you write xml-doc for a namespace? And if yes, how and where?

I would think, if it is possible, maybe an almost empty file like this:

/// <summary>
/// This namespace contains stuff
/// </summary>
namespace Some.Namespace
{

}

But will that work? Since you... "declare", or at least use the namespace in all the other files as well... and what would happen if you wrote an xml-documentation thing somewhere else on the same namespace? Would one be gone? Or would they be merged somehow?

A: 

It is not possible to put comments on namespaces.

UseNamespaceDocSummaries on http://ndoc.sourceforge.net/content/documenters.htm

Kirtan
+6  A: 

NDoc supports this by recognising a special NamespaceDoc class located in each namespace, and using the documentation from that. I haven't tried it, but Sandcastle appears to support the same trick.

Edit: For example:

namespace Some.Namespace
{
    /// <summary>
    /// This namespace contains stuff
    /// </summary>
    public static class NamespaceDoc
    {
    }
}
Tim Robinson
So, NamespaceDoc directly? Do I put one in each directory then kind of? To have a comment for each of them...
Svish
Yep, will paste an example into my answer.
Tim Robinson
+4  A: 

Sandcastle does not support the NamespaceDoc directly, but if you use Sandcastle Help File Builder you can use the NamespaceDoc class mentioned by Tim.

namespace Example
{
    /// <summary>
    ///   <para>
    ///     Summary
    ///   </para>
    /// </summary>
    /// <include file='_Namespace.xml' path='Documentation/*' />
    internal class NamespaceDoc
    {
    }
}

SCHB also extends the syntax slightly and allows embedding code examples straight from code files. An example _Namespace.xml:

<?xml version="1.0" encoding="utf-8" ?>
<Documentation>
  <summary>
    <h1 class="heading">Example Namespace</h1>
    <para>
      This namespace is used in the following way:
    </para>

    <code source="Examples\Class.cs" lang="cs"></code>
    <code source="Examples\Class.vb" lang="vbnet"></code>

 <para>
   Hopefully this helps!
 </para>
  </summary>
</Documentation>

Including documentation in XML file allows you to write short summary in code and larger description in a separate XML file for the help file. This way the code isn't cluttered with all the details and remains easily readable.

Mikko Rantanen
Iiinteresting... Why "Documentation/*" as path?
Svish
Oh. It's an XPath expression to the _Namespace.xml. It is possible to store all the documentation in same XML file and just include these based on their path, ie. path='Documentation/Namespace/*' etc. The example XML uses root tag `Documentation/*` and is class specific so the Path just includes everything inside the root tag.
Mikko Rantanen
+1  A: 

If using Mono's mdoc documentation system, you can document namespace members by editing the ns-*.xml documentation files.

See the mdoc file format documentation for more details.

jonp