accessor-order
What it does
Section titled “What it does”Reports a property or event whose accessors are in the wrong order: get goes before set or init, and add before remove. The fix swaps the two accessors; it is not offered when a comment stands between them or inside them.
Why it matters
Section titled “Why it matters”Readers expect to meet the reading accessor first and the writing one second. One order in all properties makes a file quick to scan and makes the odd one out stand out.
Example
Section titled “Example”class A { int P { set { } get { return 1; } } event System.Action E { remove { } add { } } int Q { set { } /* why */ get { return 1; } }}class A { int P { get { return 1; } set { } } event System.Action E { add { } remove { } } int Q { set { } /* why */ get { return 1; } }}Configuration
Section titled “Configuration”csharp: lint: rules: accessor-order: warn # off (default), warn, errorEnabled by the presets: csharp/stylecop.
Suppress one line with sudsy-disable-next-line accessor-order in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| StyleCop | SA1212 |
full |
| StyleCop | SA1213 |
full |