【问题标题】:What's the proper way to comment a constructor in a generic class?在泛型类中注释构造函数的正确方法是什么?
【发布时间】:2011-07-29 02:48:55
【问题描述】:

评论这个的正确方法是什么?

/// <summary>
/// Initializes a new instance of the <see cref="Repository"/> class.
/// </summary>
/// <param name="unitOfWork">The unit of work.</param>
public Repository(IUnitOfWork unitOfWork)
{
    this.UnitOfWork = unitOfWork;
}

VS 抱怨它:

警告 11 XML 注释 'Data.Repository.Repository(Data.IUnitOfWork)' 具有 cref 属性 不可能的“存储库” 已解决 C:\Projects\xx\yy\DataAccess\Repository.cs 35 58 数据

【问题讨论】:

    标签: c# visual-studio visual-studio-2010 stylecop xml-documentation


    【解决方案1】:

    你需要使用花括号:

    /// <summary>
    /// Initializes a new instance of the <see cref="Repository{T}"/> class.
    /// </summary>
    

    对于每个typeparam,只需在大括号中添加一个附加值,用逗号分隔。

    【讨论】:

    • 您也可以使用尖括号作为 XML 实体 &amp;lt;T&amp;gt;。当然,花括号更方便:)
    • 顺便说一句,“初始化存储库类的新实例。” (不带 标签)也适用于 StyleCop。
    • 另外,如果你有多个泛型类型,你可以这样做:&lt;see cref="KeyedCollection{TKey,TItem}"/&gt;
    【解决方案2】:

    StyleCop 已经定义了它应该如何look like

    如果类包含泛型参数,则可以使用以下两种格式之一在 cref 链接中对其进行注释:

    /// <summary>
    /// Initializes a new instance of the <see cref="Customer`1"/> class.
    /// </summary>
    public Customer()
    {
    }
    
    /// <summary>
    /// Initializes a new instance of the <see cref="Customer{T}"/> class.
    /// </summary>
    public Customer()
    {
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      • 2013-11-09
      • 2011-08-10
      • 1970-01-01
      • 2017-05-21
      • 2019-03-30
      • 1970-01-01
      相关资源
      最近更新 更多