Re: Reasoning behind the EventHandler(object, EventArgs) signature
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Jan 2007 09:55:39 +0100
I guess for the same reasons that any good architect will impose some sort of order on any framework they design.
The signature reassures the developer that a certain behaviour is expected and that the sender of the event and some kind of event argument, either raw or derived, will be provided. A void return type is also imposing order and suggesting that info will be passed back in the event arguments.
Creating your own delegates is perfectly acceptable but, if you were writing any sort of commercial software, the choice would be nonsense because it wouldn't fit with the plan.
Systems that use reflection to discover the capabilities of a component, and there are lots of them these days, are also aware of the signature so things like databinding use these events in the data change notification system.
You would be strongly advised not to break what doesn't need fixing.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
John B wrote:
What is the reasoning for recommending that all events have the signature EventHandler(object sender, EventArgs e)..
Obviously I can create a custom delegate
delegate void FooHandler(string foo)
and event FooHandler FooHappened
What are the benefits of creating derived eventargs classes for each event instead of creating the delegate which is much easier IMO.
Am I missing something?
Cheers
JB
- References:
- Prev by Date: GAC vs *.exe.config (and %path%)
- Next by Date: Re: C# ScrollBar and Label
- Previous by thread: Reasoning behind the EventHandler(object, EventArgs) signature
- Next by thread: Re: Reasoning behind the EventHandler(object, EventArgs) signature
- Index(es):
Relevant Pages
|