Skip to content

inheritdoc is per member? #17326

Closed
Closed

Description

@JuanZamudioGBM

For example with this interface:

/// <summary>
/// You may have some primary information about this interface.
/// </summary>
public interface ITestInterface
{
    /// <summary>
    /// Method documentation.
    /// </summary>
    void Method();
}

///<inheritdoc cref="ITestInterface"/>
public class TestClass : ITestInterface
{
    public void Method()
    {
    {
}

Method in TestClass will inherit the documentation also or do I have to add another <nheritdoc /> in Method as well?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Activity

  1. BillWagner commented on Mar 4, 2020

    @BillWagner
    Member

    /cc @mikadumont

    Can you provide the answer? Then, we can get this doc updated.

  2. mikadumont commented on Mar 4, 2020

    @mikadumont
    Contributor

    The method in TestClass will inherit the documentation also and dont need to add another inheritdoc tag.

  3. JuanZamudioGBM commented on Mar 4, 2020

    @JuanZamudioGBM
    Author

    @mikadumont In that case there will be any changes in CS1591?

    Right now if I remove the documentation from the method I get a warning,

  4. mikadumont commented on Mar 4, 2020

    @mikadumont
    Contributor

    Adding @sharwell

  5. sharwell commented on Mar 4, 2020

    @sharwell
    Contributor

    The CS1591 warning would be related to dotnet/roslyn#40325

    /cc @dotnet/roslyn-compiler

  6. BillWagner commented on Mar 5, 2020

    @BillWagner
    Member

    Thanks for helping determine the correct update. I've added this to our backlog for when we next update this article.

  7. 5 remaining items

  8. BillWagner commented on May 19, 2021

    @BillWagner
    Member

    reopening to address as part of updating the XML section

  9. removed
    won't fix
    on May 19, 2021
  10. ozdotnet commented on Mar 14, 2024

    @ozdotnet

    Hi @BillWagner, Is this fixed with #23540? I'm on Visual Studio 2022 17.9.3 and using .NET 6.0 and I still encounter this.

    Let's say I have an interface:

    ///<summary>
    /// Interface IFoo summary
    ///</summary>
    public interface IFoo
    {
        ///<summary>
        /// Foo method
        ///</summary>
        void Foo();
    }

    And it's implementation:

    /// <inheritdoc />
    public class Foo : IFoo
    {
        public void Foo() { ... }
    }

    Adding /// <inheritdoc /> at class level should be enough (also based on this documentation: Recommended XML documentation tags for a class and its members - C# | Microsoft Learn. But I'm still getting the CS1591 warning for the method. Am I doing something wrong?

  11. added
    okr-quality
    on Mar 14, 2024
  12. ozdotnet commented on Apr 2, 2024

    @ozdotnet

    Hi @mikadumont, Can someone help with my question above please. Based on documentation adding <inheritdoc /> on class level should be sufficient, and it is indeed sufficient. But warning CS1591 keeps popping up in the IDE for the underlying methods. Does the analyser have to be updated also? Thanks

  13. sharwell commented on Apr 2, 2024

    @sharwell
    Contributor

    Based on documentation adding <inheritdoc /> on class level should be sufficient, and it is indeed sufficient ...

    The <inheritdoc/> at class level is not necessary for (and is ignored by) methods. The method receives default inherited documentation because it implements an interface member.

    But warning CS1591 keeps popping up in the IDE for the underlying methods.

    This was covered by a comment above. We have no control over this.
    #17326 (comment)

    In projects I own and maintain, I generally disable three diagnostics to avoid noise:
    https://github.com/dotnet/roslyn-analyzers/blob/332dd9ab9ec226d410cc4f42f7ebe24d4fdeb117/Directory.Build.props#L34-L46

  14. ozdotnet commented on Apr 3, 2024

    @ozdotnet

    Thanks for your answer.
    Just one remark:

    The <inheritdoc/> at class level is not necessary for (and is ignored by) methods.

    This contradicts with what I read on this page: Recommended XML documentation tags for a class and its members - C# | Microsoft Learn:

    Note that when you add the tag to a type, all members will inherit the comments as well.

  15. sharwell commented on Apr 4, 2024

    @sharwell
    Contributor

    I'm not sure where that note came from, but as the implementer of <inheritdoc/> I'm fairly confident that it is not necessary. If that limitation does somehow exist, it would be part of the documentation pipeline and not part of Roslyn's handling of the feature.

    Also, the statement is not technically wrong, it's just misleading since it's easy to interpret a statement like that as implying the inverse is true.

  16. khlr commented on Jan 10, 2025

    @khlr

    I'm not sure if I correctly understand your last comment, @sharwell ...
    What is "that limitation"?

    Well in the end it seems to necessary to decorate each and every member with <inheritdoc/>. When it's only done at class level, VS keeps showing the warnings... Too bad it doesn't work at class level 😐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnet-csharp/svcfundamentals/subsvcokr-quality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions