I think there is a good reason for this agreement.
Take (and expand) the @erikkallen example:
void SomethingChanged(object sender, EventArgs e) { EnableControls(); } ... MyRadioButton.Click += SomethingChanged; MyCheckbox.Click += SomethingChanged; MyDropDown.SelectionChanged += SomethingChanged; ...
This is possible (and was from .Net 1 to generics) because covariance is supported.
Your question makes sense if you go from top to bottom - that is, you need an event in your code, so you add it to your control.
However, the agreement is to simplify the recording of components in the first place. You know that for any event the main template will work (object sender, EventArgs e).
When you add an event, you do not know how it will be used, and you do not want to arbitrarily restrict developers using your component.
Your example of a generic, strongly typed event makes sense in your code, but will not match other components written by other developers. For example, if they want to use your component with the above:
In this example, an additional type constraint simply creates pain for the remote developer. Now they need to create a new delegate just for your component. If they use the load of your components, they may need a delegate for each of them.
I believe that the agreement deserves attention for anything external or that you expect to use outside the close command.
I like the idea of common args events - I'm already using something similar.
Keith Sep 17 '09 at 12:31 2009-09-17 12:31
source share