According to http://msdn.microsoft.com/en-us/library/h0eyck3s%28VS.71%29.aspx the sender parameter in a C# event handler "is always of type object, even if it is possible to use a more specific type."
This leads to lots of event handling code like:-
RepeaterItem item = sender as RepeaterItem
if (RepeaterItem != null) { /* Do some stuff */ }
Now, in my case, I'm working with custom C# events (rather than built-in ASP.NET events, no ASP.NET at all involved so far), so I definitely don't have to worry about accidentally performing an operation on e.g. a GridView's Header.
That said, why does the convention advise against declaring an event handler with a more specific type? :-
MyType
{
public event MyEventHander MyEvent;
}
...
delegate void MyEventHander ( MyType sender, MyEventArgs e );
Am I missing a gotcha?
Edit
Just trying something on for size, it occurs to me that you could expand on EventHandler<TArgs> with:-
public class EventArgs<TContent> : EventArgs
{
public TContent Content { get; set; }
}
public delegate void EventHandler<TContent>
( object sender, EventArgs<TContent> e );
Does that look smelly?
Edit 2
Before I accept an answer, I should say for posterity that I agree with the general sentiment in the answers the convention is to use object even when it is possible to use a more specific type, and in real-world programming it is important to follow the convention.
Thanks for your answers!