Home > database >  Inheriting base constructor parameter <summary> in a derived class C#
Inheriting base constructor parameter <summary> in a derived class C#

Time:07-23

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 derrived 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)
    {
    }
}

CodePudding user response:

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 derrived 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.
  • Related