TypeName | SA1213EventAccessorsMustFollowOrder |
CheckId | SA1213 |
Category | Ordering Rules |
An add accessor appears after a remove accessor within an event.
A violation of this rule occurs when an add accessor is placed after a remove accessor within an event. To comply with this rule, the add accessor should appear before the remove accessor.
For example, the following code would raise an instance of this violation:
public event EventHandler NameChanged
{
remove { this.nameChanged -= value; }
add { this.nameChanged += value; }
}
The code below would not raise this violation:
public event EventHandler NameChanged
{
add { this.nameChanged += value; }
remove { this.nameChanged -= value; }
}
To fix an instance of this violation, place the add accessor before the remove accessor.
[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1213:EventAccessorsMustFollowOrder", Justification = "Reviewed.")]
#pragma warning disable SA1213 // EventAccessorsMustFollowOrder
#pragma warning restore SA1213 // EventAccessorsMustFollowOrder