0

This is a weird question but is there a feature on C# or in Visual Studio that allows one to add a default comment to an overridden abstract method? For example.

class A
{
    // I am the default comment. Use this method to Initialize bla bla.
    protected abstract void Method();
}

class B : A
{
    protected override void Method()
    {
        // I am the default comment. Use this method to Initialize bla bla.
        ...
    }
}

class C : A
{
    protected override void Method()
    {
        // I am the default comment. Use this method to Initialize bla bla.
        ...
    }
}

Then all the classes that inherit shall also inherit the default comment that you set for abstract method.

I'm using Microsoft Visual Studio Enterprise 2017 Version 15.8.2.

  • 1
    See https://stackoverflow.com/a/7571614/558486 and [Using the Tag](http://tunnelvisionlabs.github.io/SHFB/docs-master/SandcastleBuilder/html/79897974-ffc9-4b84-91a5-e50c66a0221d.htm) – Rui Jarimba Nov 06 '18 at 12:37
  • 1
    the is a keyword for the third party library Sandcastle. It is not supported by Visual Studio. – gofal3 Nov 06 '18 at 12:43
  • IMHO code should speak for itself. Renaming Method to Initialize will be clear that this method initializes class and does not require any comments. – Renatas M. Nov 06 '18 at 12:45
  • @gofal3 I wasn't aware of that, I was convinced it was an "official" tag. Funny thing - even Resharper generates this tag when creating derived classes or override methods.... – Rui Jarimba Nov 06 '18 at 12:49
  • @Reniuz yes code should speak for itself, but class libraries etc do require decent documentation at the class and method level. Imagine if the methods and classes in the .NET Framework didn't use XML documentation? ;-) – Rui Jarimba Nov 06 '18 at 12:50
  • 2
    But you want to inherit comment inside method body. Your abstract method should have xml documentation and it will lead developer who will implement that method to read it and implement it correctly. – Renatas M. Nov 06 '18 at 12:58

1 Answers1

0

There is no such built-in in VS but you can use other technologies or libraries like SandCastle or Roslyn probably to get this done

Rahul
  • 76,197
  • 13
  • 71
  • 125