Navigation:  StyleCop 4.3 > StyleCop 4.3 Rules > Documentation Rules >

SA1623: PropertySummaryDocumentationMustMatchAccessors

Previous pageReturn to chapter overviewNext page
StyleCop 4.3

Send comments on this topic.

SA1623: PropertySummaryDocumentationMustMatchAccessors

Glossary Item Box

TypeName

PropertySummaryDocumentationMustMatchAccessors

CheckId

SA1623

Category

Documentation Rules

 

Cause

The documentation text within a C# property’s <summary> tag does not match the accessors within the property.

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: http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.

A violation of this rule occurs if the property’s summary documentation does not match the accessors within the property.

The property’s summary text must begin with wording describing the types of accessors exposed within the property. If the property contains only a get accessor, the summary must begin with the word “Gets”. If the property contains only a set accessor, the summary must begin with the word “Sets”. If the property exposes both a get and set accessor, the summary text must begin with “Gets or sets”.

For example, consider the following property, which exposes both a get and set accessor. The summary text begins with the words “Gets or sets”.

  /// <summary>

  /// Gets or sets the name of the customer.

  /// </summary>

  public string Name

   {

      get { return this.name; }

      set { this.name = value; }

   }

 

If the property returns a Boolean value, an additional rule is applied. The summary text for Boolean properties must contain the words “Gets a value indicating whether”, “Sets a value indicating whether”, or “Gets or sets a value indicating whether”. For example, consider the following Boolean property, which only exposes a get accessor:

  /// <summary>

  /// Gets a value indicating whether the item is enabled.

  /// </summary>

  public bool Enabled

   {

      get { return this.enabled; }

   }

 

How to Fix Violations

To fix a violation of this rule, update the property’s summary text so that the description begins with the proper wording, depending upon the type of the property and the types of accessors within the property.

 


© Microsoft Corporation. All Rights Reserved.