how to read xml comment from Property in constructor?

Viewed 175
public class MyClass {
    

    /// <summary>
    ///   My awesome class
    /// </summary>
    /// <param name="i_a">This is test of A</param>
    /// <param name="i_b">This is test of B</param>
    public MyClass(string i_a, string i_b){
      A = i_a;
      B = i_b;
    }

    /// <summary> This is test of A </summary>
    public string A {get;}

    /// <summary> This is test of B </summary>
    public string B {get;}

}

I want to add in param the same info as in Properties, of course, without duplication. I tried with:

Inheritdoc

It does not display the documentation when you are creating the instance.

/// <param name="i_a"><inheritdoc cref="A" select="summary" /></param>
/// <param name="i_b"><inheritdoc cref="B" select="summary" /></param>

See or see also link

It creates a link to the property, so that it is possible to navigate to it. But this is not what I want.

/// <param name="i_a"><see cref="A"/></param>
/// <param name="i_b"><see cref="B"/></param>

My goal

I want to see the documentation of the parameter during the constructor of the class like without duplicate the code comment.

var test = new MyClass() // start entering the parameters I want to see the documentation of each parameter.

It is possible?

1 Answers

This is possible. The inheritdoc should work anywhere. There are two problems in your solution with inheritdoc:

  1. The attribute select="summary" selects also the <summary> tag itself. And it searches this tag relatively to the current inheritdoc location. In your case it searches for param/summary. See the documentation for my tool VSdocman at https://www.helixoft.com/files/vsdocman/help/inheritdoc.html

So the correct value should be "/summary/node()".

  1. I was surprised to find that inheritdoc tag now uses path parameter instead of the older select. It seems that in some contexts both attributes are supported in VS Intellisense and in some contexts (including the param tag) only the path is recognized.

So your comment should be:

/// <summary>
///   My awesome class.
///   Just a proof that old 'select' attribute works here.
///   <inheritdoc cref="A" select="/summary/node()" />
/// </summary>
/// <param name="i_a"><inheritdoc cref="A" path="/summary/node()" /></param>
/// <param name="i_b"><inheritdoc cref="B" path="/summary/node()" /></param>
public MyClass(string i_a, string i_b)
{
    A = i_a;
    B = i_b;
}
Related