SA1213: EventAccessorsMustFollowOrder

StyleCop

TypeName

EventAccessorsMustFollowOrder

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.