首页 > 解决方案 > 有没有办法使用在一个?

问题描述

我正在使用 XML 标记来记录我的程序,因此当我将鼠标悬停在我的类、方法等上时,我可以看到描述。我想在我的一个类上显示一个列表,如下所示:

/// <remarks>
/// <b>List of methods below</b>
/// <list type="table">
///     <listheader>
///         <term>
///             <see cref="MyMethod()"/>
///         </term>
///         <description>
///             <inheritdoc cref="MyMethod()"/>
///         </description>
///     </listheader>
/// </list>
/// </remarks>
public class MyClass
{
    /// <summary>
    /// Description of MyMethod()
    /// </summary>
    public void MyMethod()
    {
        // Do something
    }
}

问题是 <inheritdoc /> 没有在预览中加载任何内容。但是,当我以完全相同的格式将 <inheritdoc /> 移到 <list> 之外时,它会完美显示。有没有办法在列表中引用 MyMethod() 的描述?

标签: c#xml

解决方案


<inheritdoc>默认情况下包括目标 XML 注释中的所有成员。如果您需要,<summary>您需要使用path属性选择它:

<inheritdoc cref="MyMethod" path='//summary/text()'/>

它应该呈现如下内容:

在此处输入图像描述


推荐阅读