简体   繁体   English

命名空间的XML文档

[英]XML-documentation for a namespace

Would you write xml-doc for a namespace? 您会为名称空间编写xml-doc吗? 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? 既然您...“声明”,或者至少也要在所有其他文件中使用名称空间...并且如果您在同一名称空间的其他位置写了xml文档的内容,会发生什么? Would one be gone? 一个人走了吗? Or would they be merged somehow? 还是会以某种方式合并?

NDoc supports this by recognising a special NamespaceDoc class located in each namespace, and using the documentation from that. NDoc通过识别位于每个名称空间中的特殊NamespaceDoc类并使用该文档中的文档来支持此操作。 I haven't tried it, but Sandcastle appears to support the same trick. 我没有尝试过,但是Sandcastle似乎支持相同的技巧。

Edit: For example: 编辑:例如:

namespace Some.Namespace
{
    /// <summary>
    /// This namespace contains stuff
    /// </summary>
    public static class NamespaceDoc
    {
    }
}

Sandcastle does not support the NamespaceDoc directly, but if you use Sandcastle Help File Builder you can use the NamespaceDoc class mentioned by Tim. Sandcastle不直接支持NamespaceDoc,但是如果您使用Sandcastle帮助文件生成器 ,则可以使用Tim提到的NamespaceDoc类。

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. SCHB还稍微扩展了语法,并允许直接从代码文件中嵌入代码示例。 An example _Namespace.xml: _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. 在XML文件中包含文档,使您可以在代码中编写简短的摘要,并在帮助文件的单独XML文件中编写较大的描述。 This way the code isn't cluttered with all the details and remains easily readable. 这样,代码就不会杂乱无章地保留所有细节,并且易于阅读。

Sandcastle Help File Builder supports comments on namespaces. 沙堡帮助文件构建器支持对名称空间的注释。 Open your Sandcastle project. 打开您的Sandcastle项目。 In Project Properties window navigate to Summaries and click on the Edit Namespace Summaries button. 在“ Project Properties窗口中,导航到“ Summaries ,然后单击“ Edit Namespace Summaries按钮。

在此处输入图片说明

You can do it in doxygen using: 您可以使用以下方法在doxygen中进行:

/// <summary>
/// description
/// </summary>
namespace name{};

Also, it's a good practice to declare your namespaces in a NameSpaces.cs file, and comment them only in this file. 另外,最好在NameSpaces.cs文件中声明名称空间,并仅在此文件中对其进行注释。

If you use Sandcastle and its "Help File Builder" you can document namespaces and Namespace-Groups using the following Code in your Projects: 如果使用Sandcastle及其“帮助文件生成器”,则可以在项目中使用以下代码记录名称空间和命名空间组:

namespace Company.Product.Widgets
{
    /// <summary>
    /// These are the namespace comments for <c>Company.Product.Widgets</c>.
    /// </summary>
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    class NamespaceDoc
    {
    }
}

If the project has namespace grouping enabled, you can also maintain the namespace group comments using a NamespaceGroupDoc class in a similar fashion. 如果项目启用了名称空间分组,则您也可以使用NamespaceGroupDoc类以类似的方式维护名称空间组注释。 The following is an example: 以下是一个示例:

namespace Company.Product
{
    /// <summary>
    /// These are the group comments for namespaces in <c>Company.Product</c>.
    /// </summary>
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    class NamespaceGroupDoc
    {
    }
}

To keep the NamespaceDoc class from appearing in the help file, leave off the public keyword and mark it with a CompilerGenerated attribute. 为了防止NamespaceDoc类出现在帮助文件中,请保留public关键字,并用CompilerGenerated属性标记它。

For Reference see here: https://ewsoftware.github.io/SHFB/html/48f5a893-acde-4e50-8c17-72b83d9c3f9d.htm 有关参考,请参见此处: https : //ewsoftware.github.io/SHFB/html/48f5a893-acde-4e50-8c17-72b83d9c3f9d.htm

If using Mono 's mdoc documentation system, you can document namespace members by editing the ns-*.xml documentation files. 如果使用Monomdoc文档系统,则可以通过编辑ns-*。xml文档文件来记录名称空间成员。

See the mdoc file format documentation for more details. 有关更多详细信息,请参见mdoc文件格式文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM