Geeks With Blogs
.net alternatives by Michel Grootjans January 2009 Entries
Elegant way to raise an event
I got fed up with this kind of code for a long time: private void personList_DoubleClick(object sender, EventArgs e) { if (ShowSelectedPerson != null) ShowSelectedPerson(this, EventArgs.Empty); } Today, a colleague of mine triggered this simple idea: private void personList_DoubleClick(object sender, EventArgs e) { ShowSelectedPerson.Raise(this, EventArgs.Empty); } This is implemented with a simple extension method public static class EventHandlerExtensions { public static void Raise(this EventHandler ......

Posted On Monday, January 19, 2009 1:24 PM

Copyright © Michel Grootjans | Powered by: GeeksWithBlogs.net