Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 923
mservidio Avatar asked Jul 29 '11 02:07

mservidio


People also ask

What is a generic constructor?

A generic constructor is a constructor that has at least one parameter of a generic type. We'll see that generic constructors don't have to be in a generic class, and not all constructors in a generic class have to be generic.

What is correct regarding the name of a constructor?

Explanation: A constructor is a simple method which has the same name as the class and hence used to create object of a class.

How do you call a constructor class?

The calling of the constructor can be done in two ways: By using this() keyword: It is used when we want to call the current class constructor within the same class. By using super() keyword: It is used when we want to call the superclass constructor from the base class.


2 Answers

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.

like image 62
AnteSim Avatar answered Sep 23 '22 17:09

AnteSim


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() { } 
like image 36
Tatranskymedved Avatar answered Sep 19 '22 17:09

Tatranskymedved