<?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: Events, Reflection and how they don&#8217;t work in C#</title>
	<atom:link href="http://www.thekua.com/atwork/2007/09/events-reflection-and-how-they-dont-work-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thekua.com/atwork/2007/09/events-reflection-and-how-they-dont-work-in-c/</link>
	<description>thekua&#039;s reflections on work related topics</description>
	<lastBuildDate>Mon, 15 Mar 2010 07:45:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Patrick</title>
		<link>http://www.thekua.com/atwork/2007/09/events-reflection-and-how-they-dont-work-in-c/comment-page-1/#comment-25443</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Wed, 27 Aug 2008 10:53:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.thekua.com/atwork/2007/09/19/events-reflection-and-how-they-dont-work-in-c/#comment-25443</guid>
		<description>The second argument is the object that you want to remove the event from. The delegate is the condition that should match before you remove the event. Here&#039;s a test case that might be useful for you:

public void ShouldRemoveAllEventThatMatchTheCriteria()
{
&#160;&#160; ClassWithEvent classWithEvent = new ClassWithEvent();
&#160;&#160;  classWithEvent.RaiseMyEvent();

&#160;&#160;  ReflectUtil.RemoveEventHandlersFrom(delegate(Delegate subject) { return subject.Method.Name.StartsWith(&quot;On&quot;); }, classWithEvent);

&#160;&#160;  classWithEvent.RaiseMyEvent();

&#160;&#160;  Assert.AreEqual(1, classWithEvent.OnEventHandledCount);
&#160;&#160;  Assert.AreEqual(2, classWithEvent.EventHandledNotStartingWithOnCount);
}</description>
		<content:encoded><![CDATA[<p>The second argument is the object that you want to remove the event from. The delegate is the condition that should match before you remove the event. Here&#8217;s a test case that might be useful for you:</p>
<p>public void ShouldRemoveAllEventThatMatchTheCriteria()<br />
{<br />
&nbsp;&nbsp; ClassWithEvent classWithEvent = new ClassWithEvent();<br />
&nbsp;&nbsp;  classWithEvent.RaiseMyEvent();</p>
<p>&nbsp;&nbsp;  ReflectUtil.RemoveEventHandlersFrom(delegate(Delegate subject) { return subject.Method.Name.StartsWith(&#8220;On&#8221;); }, classWithEvent);</p>
<p>&nbsp;&nbsp;  classWithEvent.RaiseMyEvent();</p>
<p>&nbsp;&nbsp;  Assert.AreEqual(1, classWithEvent.OnEventHandledCount);<br />
&nbsp;&nbsp;  Assert.AreEqual(2, classWithEvent.EventHandledNotStartingWithOnCount);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: koolguycg</title>
		<link>http://www.thekua.com/atwork/2007/09/events-reflection-and-how-they-dont-work-in-c/comment-page-1/#comment-25406</link>
		<dc:creator>koolguycg</dc:creator>
		<pubDate>Wed, 27 Aug 2008 03:12:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.thekua.com/atwork/2007/09/19/events-reflection-and-how-they-dont-work-in-c/#comment-25406</guid>
		<description>Hi,

Can you please tell me how to ge the second argument (objectWithEvent) in this call

ReflectUtil.RemoveEventHandlersFrom(
 delegate(Delegate subject) { return subject.Method.Name.StartsWith(&quot;On&quot;); },
  objectWithEvent);

I need this urgently... please help!!!!


Thanks
Kool</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Can you please tell me how to ge the second argument (objectWithEvent) in this call</p>
<p>ReflectUtil.RemoveEventHandlersFrom(<br />
 delegate(Delegate subject) { return subject.Method.Name.StartsWith(&#8220;On&#8221;); },<br />
  objectWithEvent);</p>
<p>I need this urgently&#8230; please help!!!!</p>
<p>Thanks<br />
Kool</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: koolguycg</title>
		<link>http://www.thekua.com/atwork/2007/09/events-reflection-and-how-they-dont-work-in-c/comment-page-1/#comment-25402</link>
		<dc:creator>koolguycg</dc:creator>
		<pubDate>Wed, 27 Aug 2008 02:12:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.thekua.com/atwork/2007/09/19/events-reflection-and-how-they-dont-work-in-c/#comment-25402</guid>
		<description>Hi,

The GetValue() call is not working... it returns null, any thoughts....

Regards,
Sourabh</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>The GetValue() call is not working&#8230; it returns null, any thoughts&#8230;.</p>
<p>Regards,<br />
Sourabh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olav Rask</title>
		<link>http://www.thekua.com/atwork/2007/09/events-reflection-and-how-they-dont-work-in-c/comment-page-1/#comment-6548</link>
		<dc:creator>Olav Rask</dc:creator>
		<pubDate>Sun, 24 Feb 2008 14:10:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.thekua.com/atwork/2007/09/19/events-reflection-and-how-they-dont-work-in-c/#comment-6548</guid>
		<description>argh.. ..should say &quot;..to retreive names of all events..&quot; in the first line..</description>
		<content:encoded><![CDATA[<p>argh.. ..should say &#8220;..to retreive names of all events..&#8221; in the first line..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olav Rask</title>
		<link>http://www.thekua.com/atwork/2007/09/events-reflection-and-how-they-dont-work-in-c/comment-page-1/#comment-6547</link>
		<dc:creator>Olav Rask</dc:creator>
		<pubDate>Sun, 24 Feb 2008 14:09:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.thekua.com/atwork/2007/09/19/events-reflection-and-how-they-dont-work-in-c/#comment-6547</guid>
		<description>Why not use GetEvents() to retreive names of all fields and then use GetField to get each field, instead of trying to cast each field to Delegate? I would think this would be cheaper if the class has lots of fields that are not events.. (depending on how much work is involved in optaining a single field using GetField)

Nice work non the less - got me on the right path :)</description>
		<content:encoded><![CDATA[<p>Why not use GetEvents() to retreive names of all fields and then use GetField to get each field, instead of trying to cast each field to Delegate? I would think this would be cheaper if the class has lots of fields that are not events.. (depending on how much work is involved in optaining a single field using GetField)</p>
<p>Nice work non the less &#8211; got me on the right path <img src='http://www.thekua.com/atwork/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
