在泛型类中注释构造函数的正确方法是什么?

mse*_*dio 29 c# stylecop visual-studio-2010 xml-documentation visual-studio

评论这个的正确方法是什么?VS抱怨它:

/// <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;
}
Run Code Online (Sandbox Code Playgroud)

警告11对"Data.Repository.Repository(Data.IUnitOfWork)"的XML注释具有无法解析的cref属性"Repository"C:\ Projects\xx\yy\DataAccess\Repository.cs 35 58数据

小智 38

你需要使用花括号:

/// <summary>
/// Initializes a new instance of the <see cref="Repository{T}"/> class.
/// </summary>
Run Code Online (Sandbox Code Playgroud)

对于每个类型参数,只需在大括号中添加一个额外的值,用逗号分隔.

  • 您还可以使用有角度的括号作为XML实体`&lt; T&gt;`.当然,花括号更方便:) (2认同)
  • BTW,"初始化Repository类的新实例." (没有<see>标签)也适用于StyleCop. (2认同)

Tat*_*ved 5

StyleCop 已经定义了它应该是什么样子

如果类包含通用参数,则可以使用以下两种格式之一在 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()
{
}
Run Code Online (Sandbox Code Playgroud)