<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Firing events with Extension Methods</title>
	<atom:link href="http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=firing-events-with-extension-methods</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Cook</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-2/#comment-63761</link>
		<dc:creator>Bryan Cook</dc:creator>
		<pubDate>Sat, 02 Apr 2011 02:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-63761</guid>
		<description>You know, you could easily just define the event with an existing delegate so that you never have to check for null.

public event EventHandler&lt;MyEventArgs&gt; OnMyEvent = delegate {};</description>
		<content:encoded><![CDATA[<p>You know, you could easily just define the event with an existing delegate so that you never have to check for null.</p>
<p>public event EventHandler&lt;MyEventArgs&gt; OnMyEvent = delegate {};</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Generation 5 &#187; Extension Methods, Nulls and this in C#</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-2/#comment-25569</link>
		<dc:creator>Generation 5 &#187; Extension Methods, Nulls and this in C#</dc:creator>
		<pubDate>Thu, 03 Jul 2008 16:34:35 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-25569</guid>
		<description>[...] Chris Brandsma works out a practical example of how extension methods can be used to fix a broken and dangerous API.  That is,  the event handling mechanism commonly used in C#: [...]</description>
		<content:encoded><![CDATA[<p>[...] Chris Brandsma works out a practical example of how extension methods can be used to fix a broken and dangerous API.  That is,  the event handling mechanism commonly used in C#: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Brandsma</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-2/#comment-23182</link>
		<dc:creator>Chris Brandsma</dc:creator>
		<pubDate>Sat, 07 Jun 2008 16:38:53 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-23182</guid>
		<description>@Alexis Rzewski,
Maintainability and readability are always top of my list for any code I write.

I fail to see how this would not be maintainable, and I still think it is very readable.

So do you not like extension methods?  Or is there something specific about my implementation that you don&#039;t like?</description>
		<content:encoded><![CDATA[<p>@Alexis Rzewski,<br />
Maintainability and readability are always top of my list for any code I write.</p>
<p>I fail to see how this would not be maintainable, and I still think it is very readable.</p>
<p>So do you not like extension methods?  Or is there something specific about my implementation that you don&#8217;t like?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexis Rzewski</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-2/#comment-23160</link>
		<dc:creator>Alexis Rzewski</dc:creator>
		<pubDate>Sat, 07 Jun 2008 15:10:43 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-23160</guid>
		<description>but what benifit did it really get you ? saving you a few keystrokes ?  for the price of future maintenability, it doesn&#039;t justify the cost...</description>
		<content:encoded><![CDATA[<p>but what benifit did it really get you ? saving you a few keystrokes ?  for the price of future maintenability, it doesn&#8217;t justify the cost&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-1/#comment-20707</link>
		<dc:creator>Greg</dc:creator>
		<pubDate>Thu, 08 May 2008 18:57:18 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-20707</guid>
		<description>I turns out that if dealing with a multi-threaded app, raising events is not so simple.
http://davebrooks.wordpress.com/2007/02/07/threading-through-the-open-window-of-opportunity/</description>
		<content:encoded><![CDATA[<p>I turns out that if dealing with a multi-threaded app, raising events is not so simple.<br />
<a href="http://davebrooks.wordpress.com/2007/02/07/threading-through-the-open-window-of-opportunity/" rel="nofollow">http://davebrooks.wordpress.com/2007/02/07/threading-through-the-open-window-of-opportunity/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 7 Links Today (2008-01-10)</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-1/#comment-17003</link>
		<dc:creator>7 Links Today (2008-01-10)</dc:creator>
		<pubDate>Thu, 10 Jan 2008 15:20:17 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-17003</guid>
		<description>[...]  Firing events with Extension Methods [...]</description>
		<content:encoded><![CDATA[<p>[...]  Firing events with Extension Methods [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; Daily Bits - December 10, 2007 Alvin Ashcraft&#8217;s Daily Geek Bits: Daily links plus random ramblings about development, gadgets and raising rugrats.</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-1/#comment-16400</link>
		<dc:creator>&#187; Daily Bits - December 10, 2007 Alvin Ashcraft&#8217;s Daily Geek Bits: Daily links plus random ramblings about development, gadgets and raising rugrats.</dc:creator>
		<pubDate>Mon, 10 Dec 2007 13:48:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-16400</guid>
		<description>[...] Firing Events with Extension Methods (via DotNetKicks) [...]</description>
		<content:encoded><![CDATA[<p>[...] Firing Events with Extension Methods (via DotNetKicks) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Judah</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-1/#comment-16371</link>
		<dc:creator>Judah</dc:creator>
		<pubDate>Fri, 07 Dec 2007 21:03:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-16371</guid>
		<description>Nifty.

FWIW, we did something similar in our .NET 2 codebase. We had a static class called DelegateInvoke, with a method to raise an event:

public static class DelegateInvoker
{
    public static Raise(EventHandler handler, object sender, T eventArgs)
    {
         if(handler != null) handler(sender, eventArgs);
    }
}

When then raised events like this:

DelegateInvoker.Raise(SomeEvent, sender, args);

That said, your use of extension methods makes for a more natural syntax.</description>
		<content:encoded><![CDATA[<p>Nifty.</p>
<p>FWIW, we did something similar in our .NET 2 codebase. We had a static class called DelegateInvoke, with a method to raise an event:</p>
<p>public static class DelegateInvoker<br />
{<br />
    public static Raise(EventHandler handler, object sender, T eventArgs)<br />
    {<br />
         if(handler != null) handler(sender, eventArgs);<br />
    }<br />
}</p>
<p>When then raised events like this:</p>
<p>DelegateInvoker.Raise(SomeEvent, sender, args);</p>
<p>That said, your use of extension methods makes for a more natural syntax.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Jarrell</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-1/#comment-16369</link>
		<dc:creator>Jeremy Jarrell</dc:creator>
		<pubDate>Fri, 07 Dec 2007 16:44:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-16369</guid>
		<description>Nice, I like it.  I&#039;ve always been really bothered that the null check just can&#039;t be built into the language and I&#039;ve always had to build a similar static helper method in a helper class.  I like this a lot better.

Nice job</description>
		<content:encoded><![CDATA[<p>Nice, I like it.  I&#8217;ve always been really bothered that the null check just can&#8217;t be built into the language and I&#8217;ve always had to build a similar static helper method in a helper class.  I like this a lot better.</p>
<p>Nice job</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niki</title>
		<link>http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/comment-page-1/#comment-16368</link>
		<dc:creator>Niki</dc:creator>
		<pubDate>Fri, 07 Dec 2007 14:41:55 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2007/12/05/firing-events-with-extension-methods/#comment-16368</guid>
		<description>Nice!

@Alex: There is no race condition here. When you invoke am event directly in your code:
  if (SomeEvent != null)
     SomeEvent(this, ...); // bad!
then someone might be changing it after the if, but before the event gets invoked. That&#039;s what the invoke-snipped you posted prevents, by copying the current event handler into a local variable.

However, if you&#039;re calling a method to fire your event (extension method or not) then the event handler is implicitly copied on the stack, unless it&#039;s passed as a ref parameter. So Cris&#039; code is not only simpler, it is also thread-safe!</description>
		<content:encoded><![CDATA[<p>Nice!</p>
<p>@Alex: There is no race condition here. When you invoke am event directly in your code:<br />
  if (SomeEvent != null)<br />
     SomeEvent(this, &#8230;); // bad!<br />
then someone might be changing it after the if, but before the event gets invoked. That&#8217;s what the invoke-snipped you posted prevents, by copying the current event handler into a local variable.</p>
<p>However, if you&#8217;re calling a method to fire your event (extension method or not) then the event handler is implicitly copied on the stack, unless it&#8217;s passed as a ref parameter. So Cris&#8217; code is not only simpler, it is also thread-safe!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

