-
Notifications
You must be signed in to change notification settings - Fork 22
SA1642
TypeName |
ConstructorSummaryDocumentationMustBeginWithStandardText |
CheckId |
SA1642 |
Category |
Documentation Rules |
The Xml documentation header for a C# constructor does not contain the appropriate summary text.
C# syntax provides a mechanism for inserting documentation for classes and elements directly into the code, through the use of Xml documentation headers. For an introduction to these headers and a description of the header syntax, see the following article: http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
A violation of this rule occurs when the summary tag within the documentation header for a constructor does not begin with the proper text.
The rule is intended to standardize the summary text for a constructor based on the access level of the constructor. The summary for a non-private instance constructor must begin with “Initializes a new instance of the {class name} class.” For example, the following shows the constructor for the Customer class.
/// <summary>
/// Initializes a new instance of the Customer class.
/// </summary>
public Customer()
{
}
It is possible to embed other tags into the summary text. For example:
/// <summary>
/// Initializes a new instance of the <see cref="Customer"/> class.
/// </summary>
public Customer()
{
}
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()
{
}
If the constructor is static, the summary text should begin with “Initializes static members of the {class name} class.” For example:
/// <summary>
/// Initializes static members of the Customer class.
/// </summary>
public static Customer()
{
}
Private instance constructors must use the summary text “Prevents a default instance of the {class name} class from being created.”
/// <summary>
/// Prevents a default instance of the Customer class from being created.
/// </summary>
private Customer()
{
}
To fix a violation of this rule, edit the summary text for the constructor as described above.
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1642:ConstructorSummaryDocumentationMustBeginWithStandardText", Justification = "Reviewed.")]
- - SA0102 - Clean Install
- - Download
- - Documentation Rules - Layout Rules - Maintainability Rules - Naming Rules - Ordering Rules - Readability Rules - Spacing Rules - Suppressions
- - Adding a custom StyleCop settings page - Adding custom rule settings - Authoring a custom styleCop rule - Authoring rules metadata - Custom CSharp Language Service - Custom MSBuild Integration - Hosting StyleCop in a Custom Environment - Installing a Custom Rule - Integrating StyleCop Into Build Environments - Integrating StyleCop into MSBuild - Writing Custom Rules for StyleCop