-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Design.DeclareEventHandlersCorrectlyRule(git)
Assembly: Gendarme.Rules.Design
Version: git
This rule will fire if an event is declared with a signature which does not match the .NET guidelines. The return type of the event should be void (because there is no good way to handle return values if multiple delegates are attached to the event). And the event should take two arguments. The first should be of type System.Object and be named 'sender'. The second should be of type System.EventArgs (or a subclass) and named 'e'. This helps tools such as visual designers identify the delegates and methods which may be attached to events. Note that .NET 2.0 added a generic System.EventHandler type which can be used to easily create events with the correct signature.
Bad example:
// the second parameter (which should be System.EventArgs or a derived class) is missing
delegate void MyDelegate (int sender);
class Bad {
public event MyDelegate CustomEvent;
}
Good example (delegate):
delegate void MyDelegate (int sender, EventArgs e);
class Good {
public event MyDelegate CustomEvent;
}
Good example (generics):
class Good {
public event EventHandler<EventArgs> CustomEvent;
}
- This rule is available since Gendarme 2.2
You can browse the latest source code of this rule on github.com
Note that this page was autogenerated (3/17/2011 1:55:44 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!