BRO1605: Property summary documentation should omit accessor with restricted access¶
A property whose setter is private or internal is documented as Gets, not Gets or sets: other code can't set it.
Replaces StyleCop SA1624.
Example¶
Before¶
public class Account
{
/// <summary>Gets or sets the balance.</summary>
public decimal Balance { get; private set; }
public void Deposit(decimal amount) => Balance += amount;
}
After¶
public class Account
{
/// <summary>Gets the balance.</summary>
public decimal Balance { get; private set; }
public void Deposit(decimal amount) => Balance += amount;
}
Why¶
Documentation describes what callers can do. For them, a property with a private setter is read-only.
How the fix works¶
Gets or sets becomes Gets (and Gets or sets a value indicating whether becomes Gets a value indicating
whether). The same goes for Gets or initializes on a property with a restricted init accessor. A private, internal or private protected setter counts as restricted; a protected or
protected internal one doesn't, since derived types can use it. The same goes for a restricted
getter: { private get; set; } is documented Sets, not Gets or sets. An internal accessor isn't
restricted when only the assembly sees the property anyway (it's in an internal class, or is internal itself):
internal class Node { public int Count { get; internal set; } } says Gets or sets. A private accessor is always
restricted.
With stylebro_summary_wording = stylesharp (StyleSharp's SST1624, see BRO1604)
any modifier on the set or init accessor makes it restricted, protected too, and the getter's modifier doesn't
count: { get; protected set; } says Gets, { private get; set; } says Gets or sets.
This rule reads documentation as XML, which needs <GenerateDocumentationFile>true</GenerateDocumentationFile>.