Skip to content

property-summary-matches-accessors

C#stylefix: unsafedefault: offcsharp/stylecop

Reports a property summary that does not start with “Gets”, “Sets” or “Gets or sets” as the accessors that are reachable from outside the type say; for bool properties “Gets a value indicating whether” and the like. The type is read from the declaration (bool, Boolean, System.Boolean). The fix replaces the start of the text and lower-cases what follows, and is unsafe.

A summary that says “Gets or sets” for a property that can only be read promises something the caller cannot do. The first words are a contract that tools and readers rely on.

Reported
...
internal class InternalProperties
{
/// <summary>The count.</summary>
protected internal int Both { get; protected set; }
/// <summary>Gets or sets the count.</summary>
protected internal int GoodBoth { get; protected set; }
...
After the fix
...
internal class InternalProperties
{
/// <summary>Gets or sets the count.</summary>
protected internal int Both { get; protected set; }
/// <summary>Gets or sets the count.</summary>
protected internal int GoodBoth { get; protected set; }
...
csharp:
lint:
rules:
property-summary-matches-accessors: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line property-summary-matches-accessors in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
StyleCop SA1623 partial a property whose type is an alias of System.Boolean (using alias) is not recognized as bool