【问题标题】:Documentation Comments (Subclass)文档注释(子类)
【发布时间】:2012-01-09 09:18:32
【问题描述】:

是否有更新文档注释以反映子类而不是基类的名称的标准方法?另外,如果确实存在一种方法,我应该练习还是避免这种方法?

例子:

class BaseClass
{
    /// <summary>
    /// Gets or sets a value associated with the name of the BaseClass
    /// </summary>
    protected string Name { get; set; }
}

class SubClass : BaseClass
{
    /// Gets or sets a value associated with the name of the Subclass <-- updated
    /// protected string Name { get; set; } <-- defined on BaseClass
}

【问题讨论】:

    标签: c# documentation comments


    【解决方案1】:

    如果您使用Sandcastle Help File Builder,您可以通过使用&lt;inheritdoc/&gt; tag 实现一定程度的描述重用。例如,您可以在基类上设置摘要,然后在派生类上使用&lt;inheritdoc/&gt; 来获取相同的内容。但是,我认为没有办法动态更改它(例如替换类名)——您要么继承整个摘要文本,要么不继承。

    【讨论】:

      【解决方案2】:

      没有。该文档仅适用于已实现的代码 - 如果您的类从其基类继承了一个方法,那么该文档也将被继承。您不能在不提供新实现的情况下“覆盖”文档。 (虽然这很有意义 - 如果实现没有改变,那么文档也不需要改变。)

      如果您以外部形式或智能感知方式浏览文档,则基类中的文档将根据需要显示,因此无需重新定义它们即可查看相应的文档。

      【讨论】:

        猜你喜欢
        • 2018-01-01
        • 1970-01-01
        • 2010-10-02
        • 2014-10-30
        • 2019-11-03
        • 1970-01-01
        • 2016-09-22
        • 2010-11-01
        • 1970-01-01
        相关资源
        最近更新 更多