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

本文关键字:方法 是什么 泛型类 注释 构造函数 | 更新日期: 2023-09-27 18:04:07

如何正确注释?

/// <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 Data

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

你需要使用大括号:

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

对于每个typeparam,只需在花括号中添加一个额外的值,用逗号分隔。

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