<inheritdoc> (C# Programming Guide)

Syntax

<inheritdoc [cref=""] [path=""]/>

InheritDoc

Inherit XML comments from base classes, interfaces, and similar methods. This eliminates unwanted copying and pasting of duplicate XML comments and automatically keeps XML comments synchronized.

Attributes

cref

Specify the member to inherit documentation from.
Already defined tags on the current member are not overridden by the inherited ones.

path

The XPath expression query that will result in a node set to show.
You can use this attribute to filter which tags to include or exclude from the inherited documentation.

Remarks

Add your XML comments in base classes or interfaces and let InheritDoc copy the comments to implementing classes.

Add your XML comments to your synchronous methods and let InheritDoc copy the comments to your asynchronous versions of the same methods.

If you want to copy the comments from a specific member you can use the cref attribute to specify the member.

Examples

// compile with: -doc:DocFileName.xml

/// <summary>
/// You may have some primary information about this class.
/// </summary>
public class MainClass
{
}

///<inheritdoc/>
public class TestClass: MainClass
{
}
// compile with: -doc:DocFileName.xml

/// <summary>
/// You may have some primary information about this interface.
/// </summary>
public interface ITestInterface
{
}

///<inheritdoc cref="ITestInterface"/>
public class TestClass : ITestInterface
{
}
// compile with: -doc:DocFileName.xml

public class InheritOnlyReturns
{
    /// <summary>In this example, this summary is only visible for this method.</summary>
    /// <returns>A boolean</returns>
    public static bool MyParentMethod(bool x) { return x; }
    
    /// <inheritdoc cref="MyParentMethod" path="/returns"/>
    public static bool MyChildMethod() { return false; }
}
// compile with: -doc:DocFileName.xml

public class InheritAllButRemarks
{
    /// <summary>In this example, this summary is visible on all the methods.</summary>
    /// <remarks>The remarks.</remarks>
    /// <returns>A boolean</returns>
    public static bool MyParentMethod(bool x) { return x; }
    
    /// <inheritdoc cref="MyParentMethod" path="//*[not(self::remarks)]"/>
    public static bool MyChildMethod() { return false; }
}

See also