BRO1004: Event accessors should follow order¶
An event's add accessor comes before its remove accessor. Replaces StyleCop SA1213.
Example¶
Before¶
using System;
public class Button
{
private EventHandler? clicked;
public event EventHandler Clicked
{
remove { this.clicked -= value; }
add { this.clicked += value; }
}
}
After¶
using System;
public class Button
{
private EventHandler? clicked;
public event EventHandler Clicked
{
add { this.clicked += value; }
remove { this.clicked -= value; }
}
}
Why¶
Subscribing comes before unsubscribing, and every other event is written that way.
How the fix works¶
The same as BRO1003: the two accessors are swapped with their comments.
Compared with StyleCop¶
Same positions and the same fixed output as StyleCop.