BRO1003: Property accessors should follow order¶
A property's or indexer's get accessor comes before its set or init accessor. Replaces StyleCop SA1212.
Example¶
Before¶
public class Account
{
private decimal balance;
public decimal Balance
{
set { this.balance = value; }
get { return this.balance; }
}
public string Owner { set; get; }
}
After¶
public class Account
{
private decimal balance;
public decimal Balance
{
get { return this.balance; }
set { this.balance = value; }
}
public string Owner { get; set; }
}
Why¶
Reading comes before writing everywhere else in .NET, so get first is what readers look for.
How the fix works¶
The fix swaps the two accessors. When each has its own lines, the comments above an accessor move with it and blank
lines stay where they are. Auto-properties ({ set; get; }) count too, like in StyleCop.
Not reported¶
- An accessor that shares a line with other code (for example
{ seton the line of the opening brace), when the accessors aren't all on one line: the fix couldn't tell what belongs to it.
Compared with StyleCop¶
Same positions and the same fixed output as StyleCop.