What's the proper way to comment a constructor in a generic class?
Asked Answered
C

2

43

What's the proper way to comment this?

/// <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 complains about it:

Warning 11 XML comment on 'Data.Repository.Repository(Data.IUnitOfWork)' has cref attribute 'Repository' that could not be resolved C:\Projects\xx\yy\DataAccess\Repository.cs 35 58 Data

Cabdriver answered 29/7, 2011 at 2:48 Comment(0)
D
56

You need to use curly braces:

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

For each typeparam, just add an additional value in the braces, delimited with a comma.

Disunion answered 29/7, 2011 at 3:0 Comment(3)
You can also use angled brackets as XML entities &lt;T&gt;. Of course, curly braces are much more convenient :)Korten
BTW, "Initializes a new instance of the Repository class." (without <see> tag) will be also OK for StyleCop.Preselector
Also, if you have multiple generic types, you can do something like this: <see cref="KeyedCollection{TKey,TItem}"/>Ambivalence
K
6

StyleCop has defined how it should look like.

If the class contains generic parameters, these can be annotated within the cref link using either of the following two formats:

/// <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()
{
}
Kuvasz answered 13/3, 2018 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.