Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.3 KB

SA1213.md

File metadata and controls

59 lines (45 loc) · 1.3 KB

SA1213

TypeName SA1213EventAccessorsMustFollowOrder
CheckId SA1213
Category Ordering Rules

Cause

An add accessor appears after a remove accessor within an event.

Rule description

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; }
}

How to fix violations

To fix an instance of this violation, place the add accessor before the remove accessor.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1213:EventAccessorsMustFollowOrder", Justification = "Reviewed.")]
#pragma warning disable SA1213 // EventAccessorsMustFollowOrder
#pragma warning restore SA1213 // EventAccessorsMustFollowOrder