C#XML抽象类中方法的文档

时间:2015-04-14 21:28:49

标签: c# xml-comments

我有一个通用的抽象基类,它有一些方法。这些方法对它们有XML注释:

/// <summary>
///     Controller for working with instances of {TModel}
/// </summary>
public abstract class BaseController<TModel> : ApiController
{
    /// <summary>
    ///     Creates a {TModel}.
    /// </summary>
    [HttpPost]
    public Task<TModel> Post([FromBody] TModel model)
    {
        ...
        return ...
    }
}

我希望能够这样实现它:

/// <summary>
///     Controller for working with instances of PersonModel
/// </summary>
public class PersonController : BaseController<PersonModel>
{
}

为PersonController生成XML注释,模仿基类上的注释。这样可以让像https://github.com/domaindrivendev/Swashbuckle这样的东西能够获取我的XML注释,并为PersonController很好地显示它们。

目前评论如下:

<?xml version="1.0"?>
<doc>
    <assembly>
        <name>MyLibrary</name>
    </assembly>
    <members>
        <member name="T:MyLibrary.PersonController">
            <summary>
                Controller for working with instances of PersonModel
            </summary>
        </member>
        <member name="T:MyLibrary.BaseController`1">
            <summary>
                Controller for working with instances of {TModel}
            </summary>
        </member>
        <member name="M:MyLibrary.BaseController`1.Post(`0)">
            <summary>
                Creates a {TModel}.
            </summary>
        </member>
    </members>
</doc>

我希望在PersonController上也包含post方法的方法文档:

...
<member name="M:MyLibrary.PersonController.Post(`0)">
    <summary>
        Creates a PersonModel.
    </summary>
</member>
...

在这一点上,我觉得我浪费了太多时间试图弄清楚如何让它做我想做的事情。你们中的任何人都可以帮我找到捷径吗?

0 个答案:

没有答案