Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 3.83 KB

SA1605.md

File metadata and controls

76 lines (57 loc) · 3.83 KB

SA1605

TypeName SA1605PartialElementDocumentationMustHaveSummary
CheckId SA1605
Category Documentation Rules

Cause

The <summary> or <content> tag within the documentation header for a C# code element is missing or empty.

Rule description

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: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments.

A violation of this rule occurs when the documentation header for a partial element (an element with the partial attribute) is missing a <summary> or <content> tag, or contains an empty <summary> or <content> tag which does not contain a description of the element. In C# the following types of elements can be attributed with the partial attribute: classes, methods.

When documentation is provided on more than one part of the partial class, the documentation for the two classes may be merged together to form a single source of documentation. For example, consider the following two parts of a partial class:

/// <summary>
/// Documentation for the first part of Class1.
/// </summary>
public partial class Class1
{
}

/// <summary>
/// Documentation for the second part of Class1.
/// </summary>
public partial class Class1
{
}

These two different parts of the same partial class each provide different documentation for the class. When the documentation for this class is built into an SDK, the tool building the documentation will either choose to use only one part of the documentation for the class and ignore the other parts, or, in some cases, it may merge the two sources of documentation together, to form a string like: "Documentation for the first part of Class1. Documentation for the second part of Class1."

For these reasons, it can be problematic to provide SDK documentation on more than one part of the partial class. However, it is still advisable to document each part of the class, to increase the readability and maintainability of the code, and StyleCop will require that each part of the class contain header documentation.

This problem is solved through the use of the <content> tag, which can replace the <summary> tag for partial classes. The recommended practice for documenting partial classes is to provide the official SDK documentation for the class on the main part of the partial class. This documentation should be written using the standard <summary> tag. All other parts of the partial class should omit the <summary> tag completely, and replace it with a <content> tag. This allows the developer to document all parts of the partial class while still centralizing all of the official SDK documentation for the class onto one part of the class. The <content> tags will be ignored by the SDK documentation tools.

How to fix violations

To fix a violation of this rule, add and fill-in a <summary> or <content> tag with a description of the code element.

The following example shows a partial class with a fill-in <summary> tag.

/// <summary>
/// Represents a customer in the database.
/// </summary>
public partial class Customer
{
}

How to suppress violations

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1605:PartialElementDocumentationMustHaveSummary", Justification = "Reviewed.")]
#pragma warning disable SA1605 // PartialElementDocumentationMustHaveSummary
#pragma warning restore SA1605 // PartialElementDocumentationMustHaveSummary