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 (like StyleCop). The same goes for a restricted
getter: { private get; set; } is documented Sets, not Gets or sets.
This rule reads documentation as XML, which needs <GenerateDocumentationFile>true</GenerateDocumentationFile>.
Compared with StyleCop¶
Same results and fixed output as StyleCop's master (unreleased), which added init accessors (StyleCop
1.2.0-beta.556 ignores them).