在一个泛型类中,如何适当地注释构造函数?

42

如何适当地对此进行评论?

/// <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注释中的cref属性'Repository'无法解析,位于'C:\ Projects \ xx \ yy \ DataAccess \ Repository.cs'的'Data.Repository.Repository(Data.IUnitOfWork)'上 35 58 Data

2个回答

53

您需要使用花括号:

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

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

2
你也可以使用尖括号作为XML实体“<T>”。当然,花括号更加方便 :) - BoltClock
2
顺便说一下,“初始化Repository类的新实例。”(不带<see>标记)对于StyleCop也是可以接受的。 - Oleg Shuruev
另外,如果您有多个通用类型,可以这样做:<see cref="KeyedCollection{TKey,TItem}"/> - Alexander

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()
{
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接