重写的方法文档

Overridden method documentation

我正在使用 C# 和 Visual Studio(2015 年,未检查其他版本)。

我对代码文档的覆盖方法有疑问。请看下面的例子

public class BaseClass
{
    public BaseClass()
    { }

    /// <summary>
    /// BaseClass.MethodName comment
    /// </summary>
    public virtual void MethodName()
    { }
}

public class InheritedClass : BaseClass
{
    public InheritedClass(): base()
    { }

    public override void MethodName()
    { }
}

public class Test
{
    public static void m()
    {
        BaseClass b = new BaseClass();
        b.MethodName();

        InheritedClass i = new InheritedClass();
        i.MethodName();

        BaseClass iasb = i;
        iasb.MethodName();
    }
}

如果我将光标移到对 MethodName() 的 3 个不同调用上,我得到:

似乎对覆盖方法的代码注释查找也不会扫描基础 classes,当覆盖方法没有 "overridden" 注释时也不会。相反,如果可能的话,我希望如果继承的 class 没有任何本地评论,则显示基础 class' 评论。此外,如果继承的 class 有本地评论,开发人员可以选择判断本地评论是否必须完全覆盖基础 class' 评论,或者本地评论是否必须以某种方式与基 class' one.

组合

有什么建议吗?

这是在 Visual Studio 2019 版本 16.4 中引入的。来自 release notes:

.NET Productivity additions in this release include the ability to configure the severity level of a code style rule directly through the editor, navigate easily up the inheritance chain with the new Go To Base command, adding null checks for all parameters, and XML documentation for overriding methods.

在那之前,似乎有一个 extension, and an MSBuild task 来完成同样的事情,方法是用 /// <inheritdoc/>.

装饰覆盖的方法