<inheritdoc>(C# 编程指南)<inheritdoc> (C# Programming Guide)

语法Syntax

<inheritdoc/>

InheritDocInheritDoc

继承基类、接口和类似方法中的 XML 注释。Inherit XML comments from base classes, interfaces, and similar methods. 这样不必复制和粘贴重复的 XML 注释,并自动保持 XML 注释同步。This eliminates unwanted copying and pasting of duplicate XML comments and automatically keeps XML comments synchronized.

备注Remarks

在基类或接口中添加 XML 注释,并让 InheritDoc 将注释复制到实现类中。Add your XML comments in base classes or interfaces and let InheritDoc copy the comments to implementing classes.

向同步方法添加 XML 注释,并让 InheritDoc 将注释复制到相同方法的异步版本中。Add your XML comments to your synchronous methods and let InheritDoc copy the comments to your asynchronous versions of the same methods.

如果要从特定成员复制注释,可以使用 cref 特性来指定成员。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
{
}

另请参阅See also