2

I am working with C# and Visual Studio (2015, made no check on other versions).

I have a problem with an overridden method for the code documentation. Please see following example

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();
    }
}

If I move the cursor over the 3 different calls to MethodName() I get:

  • over b:
    enter image description here

  • over i:
    enter image description here

  • over iasb:
    enter image description here

It seems that code comments lookup on overridden methods doesn't scan also base classes, neither when the overridden method has no "overridden" comment. Instead I would like, if possible, that if the inherited class does not have any local comment the base class' comment is displayed. In addition it would also be nice that if the inherited class has a local comment, developer had the option to tell whether the local comment has to override completely the base class' comment, or if the local comment has to be combiled in some way with base class' one.

Any suggestion?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Tomaso Tosolini
  • 233
  • 2
  • 9

1 Answers1

2

This was introduced in Visual Studio 2019 version 16.4. From the 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.

Before then, it looks like there's an extension, and an MSBuild task to accomplish the same thing, by decorating the overridden method with /// <inheritdoc/>.

canton7
  • 37,633
  • 3
  • 64
  • 77