6

I would like to know whenever is it possible to refer/inherit description of base constructors parameters. Based on my research I was able to figure out how to refer to description of a property however so far it does not seem to be possible to refer to a constructor parameter (signature matching being the main problem).

<param name="number"><inheritdoc cref="Number" path="/summary"/></param>

    


    public class A
{
    /// <summary>
    /// Some description
    /// </summary>
    /// <param name="param">I want to inherit this summary in a derived class.</param>
    public A(string param)
    {

    }
}

public class B : A
{
    /// <summary>
    /// Some decription
    /// </summary>
    /// <param name="param">I would like inherit description from the base class. </param>
    /// <param name="newParam">Some new description.</param>
    public B(string param, int newParam) : base(param)
    {
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2184057
  • 924
  • 10
  • 27
  • Not really. The catch is that what I want to do is to inherit summary description for base constructor parameters and define manually description for new ones. Inheritdoc works great but only If you want to take everything from parent and nothing from yourself. – user2184057 Jul 22 '22 at 11:19

1 Answers1

3

Inheritdoc works great but only If you want to take everything from parent and nothing from yourself.

Not really, you can use the <inheritdoc> tag to grab what you need from the base class. Everything or the value of a specific node through XPath expression as shown in:

Is it possible to inherit documentation from specific parameters?

In your case, you should have something like:

public class A
{
    /// <summary>
    /// Some description
    /// </summary>
    /// <param name="param">I want to inherit this summary in a derived class.</param>
    public A(string param)
    {

    }
}

public class B : A
{
    /// <summary>
    /// Some decription
    /// </summary>
    /// <param name="param"><inheritdoc cref="A(string)" path="/param[@name='param']"/></param>
    /// <param name="newParam">Some new description.</param>
    public B(string param, int newParam) : base(param)
    {
    }
}

Where:

  • cref="A(string)" Specifies the base class ctor.
  • path="/param[@name='param']" Specifies the required param.
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
dr.null
  • 4,032
  • 3
  • 9
  • 12
  • 1
    Thank you I've checked and it works. It's not perfect as it's really easy to break it by renaming variable but allows for DRY in documentation which is great. It's a real shame that there is so little support in terms of DRY for documentation. I am accepting this as an answer. – user2184057 Jul 22 '22 at 20:06