Inherit comments from a virtual object

Asked

Viewed 64 times

2

How can I inherit the comments within the tag <summary> of an object?

I have the following class:

class BASE
{
    /// <summary>
    /// String de Conexão a base de dados.
    /// </summary>
    public virtual string CONN { get; set; }

    /// <summary>
    /// Carregar DataTable do Modelo.
    /// </summary>
    /// <param name="Select">Select do Modelo.</param>
    /// <returns></returns>
    public virtual DataTable LOAD(string Select) => new DataTable();
}

When I create new classes from it, they don’t inherit the comments through the override Ex:

class SQL : BASE
{
    public override string CONN { get => base.CONN; set => base.CONN = value; }

    public override DataTable LOAD(string Select)
    {
        return base.LOAD(Select);           
    }
}

2 answers

3


With Resharper (and possible other tools), you can replicate the comment with Alt+Enter in the setting, you will have an option to copy the base documentation.

Even with this possibility, be aware that when you are overwriting a method it no longer does what the summary said, even if you call your base after. The right thing to do is to make a new summary of what your method does.

  • 3

    And if you still want to put some note, you can use the tag <see> pointing to the reference. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/see

  • Very good, did not know this tag. + 1

2

You also have the possibility to inherit the documentation as you wish. To do this use the <inheritdoc cref=""/>

Example:

/// <inheritdoc cref="object.ToString"/>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.