TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

Rule:  9@104

This rule is Obsolete
Synopsis:Use the sender/arguments signature for event handlers
Language:C#
Severity Level:6
Category:Delegates and events


Description:

The goal of this rule is to have a consistent signature for all event handlers. In general, the event handler's signature should look like this:

public delegate void MyEventHandler(object sender, EventArgs arguments)

Using the base class as the sender type allows derived classes to reuse the same event handler.

The same applies to the arguments parameter. It is recommended to derive from the .NET Framework's EventArgs class and add your own event data. Using such a class prevents cluttering the event handler?s signature, allows extending the event data without breaking any existing users, and can accommodate multiple return values (instead of using reference fields). Moreover, all event data should be exposed through properties, because that allows for verification and preventing access to data that is not always valid in all occurrences of a certain event.

Note:

If possible use the generic EventHandler instead of defining your own EventHandler delegate.