<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Internal And Protected Virtual</title>
	<atom:link href="http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/feed/" rel="self" type="application/rss+xml" />
	<link>http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/</link>
	<description>Random Thoughts about C#, VS, WinForms, WPF and .NET in General</description>
	<lastBuildDate>Tue, 22 Dec 2009 20:10:23 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: marlongrech</title>
		<link>http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-30</link>
		<dc:creator>marlongrech</dc:creator>
		<pubDate>Tue, 01 Jan 2008 14:15:20 +0000</pubDate>
		<guid isPermaLink="false">http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-30</guid>
		<description>COOL Article ... I love it....</description>
		<content:encoded><![CDATA[<p>COOL Article &#8230; I love it&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: agsmith</title>
		<link>http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-23</link>
		<dc:creator>agsmith</dc:creator>
		<pubDate>Tue, 18 Dec 2007 17:42:49 +0000</pubDate>
		<guid isPermaLink="false">http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-23</guid>
		<description>Yes I see what you mean. I&#039;m still not sure I&#039;m sold on images but I&#039;ll play around and if I can&#039;t find an acceptable approach I&#039;ll switch over to images as well.</description>
		<content:encoded><![CDATA[<p>Yes I see what you mean. I&#8217;m still not sure I&#8217;m sold on images but I&#8217;ll play around and if I can&#8217;t find an acceptable approach I&#8217;ll switch over to images as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Smith</title>
		<link>http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-22</link>
		<dc:creator>Josh Smith</dc:creator>
		<pubDate>Tue, 18 Dec 2007 14:14:52 +0000</pubDate>
		<guid isPermaLink="false">http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-22</guid>
		<description>Nice code.  Isn&#039;t it a pain to deal with code formatting in a WordPress blog?  Now you see why I take screenshots of my code and just display that image. ;)</description>
		<content:encoded><![CDATA[<p>Nice code.  Isn&#8217;t it a pain to deal with code formatting in a WordPress blog?  Now you see why I take screenshots of my code and just display that image. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: agsmith</title>
		<link>http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-18</link>
		<dc:creator>agsmith</dc:creator>
		<pubDate>Sun, 16 Dec 2007 15:51:11 +0000</pubDate>
		<guid isPermaLink="false">http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-18</guid>
		<description>Yes, you can check if its nested (using IsNested) and see who is nesting it (using its DeclaringType). I actually updated the article last night to do just that.

Well I don&#039;t see a way to allow the BeginInvoke version to be done directly. I think if you need to call one of these methods using BeginInvoke that you will need to use a delagate around another method and that method will call the internal and protected method. I checked the delegate call using Invoke on the delegate and it works properly.</description>
		<content:encoded><![CDATA[<p>Yes, you can check if its nested (using IsNested) and see who is nesting it (using its DeclaringType). I actually updated the article last night to do just that.</p>
<p>Well I don&#8217;t see a way to allow the BeginInvoke version to be done directly. I think if you need to call one of these methods using BeginInvoke that you will need to use a delagate around another method and that method will call the internal and protected method. I checked the delegate call using Invoke on the delegate and it works properly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Smith</title>
		<link>http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-17</link>
		<dc:creator>Josh Smith</dc:creator>
		<pubDate>Sun, 16 Dec 2007 14:48:22 +0000</pubDate>
		<guid isPermaLink="false">http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-17</guid>
		<description>I was under the misimpression that all anonymous methods were in a compiler-generated nested class, so that&#039;s what I meant.  Thanks for pointing out that they are only sometimes in a separate class.  I should have specified that in my original comment.  Can you check if the type which contains the caller method is nested within the type which contains the callee method using reflection?

With the delegates, I was thinking that someone invoked the &quot;protected AND internal&quot; method directly via the delegate.  I hadn&#039;t considered the BeginInvoke problem, but that sounds like a definite no-no for your test method to deal with.  

I&#039;m interested to see how you handle these scenarios.

Thanks,
Josh</description>
		<content:encoded><![CDATA[<p>I was under the misimpression that all anonymous methods were in a compiler-generated nested class, so that&#8217;s what I meant.  Thanks for pointing out that they are only sometimes in a separate class.  I should have specified that in my original comment.  Can you check if the type which contains the caller method is nested within the type which contains the callee method using reflection?</p>
<p>With the delegates, I was thinking that someone invoked the &#8220;protected AND internal&#8221; method directly via the delegate.  I hadn&#8217;t considered the BeginInvoke problem, but that sounds like a definite no-no for your test method to deal with.  </p>
<p>I&#8217;m interested to see how you handle these scenarios.</p>
<p>Thanks,<br />
Josh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: agsmith</title>
		<link>http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-16</link>
		<dc:creator>agsmith</dc:creator>
		<pubDate>Sun, 16 Dec 2007 06:07:47 +0000</pubDate>
		<guid isPermaLink="false">http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-16</guid>
		<description>Well anonymous methods are just &quot;syntactic sugar&quot;. If you look at the il for a class that uses them, you should see either a static method, an instance method or a nested class. The first is used if the anonymous method doesn&#039;t reference any instance member of the class instance declaring it (and doesn&#039;t capture locals). The second is if the am does reference an instance member. The last is used if you reference/capture a local variable. There&#039;s a great article on am here - http://www.theserverside.net/tt/articles/showarticle.tss?id=AnonymousMethods

So for anonymous methods, the first two would work fine since their declaring type is that of the defining or derived class. The last one would actually be a problem. Actually nested classes should have access to all members of the nesting class (even privates) so I have to make a change in the routine to allow for this. I&#039;ll update the article.

With regards to delegates, I think it depends on how you mean. If you mean that someone calls the internal and protected member within the delegate callback then that method is the caller and the check would be ok. However, if you mean that the delegate&#039;s target is the method that is doing the checking (the callee), then it may not work. If you do a begininvoke on the delegate (which results in it running in a separate thread), then it will result in an exception even if the begininvoke was initiated by the defining or derived class. That class won&#039;t even be in the callstack when the delegate is invoked. However, I believe a direct invocation of the delegate should work. If you could give a specific example or examples, I&#039;ll be sure to look into it more.</description>
		<content:encoded><![CDATA[<p>Well anonymous methods are just &#8220;syntactic sugar&#8221;. If you look at the il for a class that uses them, you should see either a static method, an instance method or a nested class. The first is used if the anonymous method doesn&#8217;t reference any instance member of the class instance declaring it (and doesn&#8217;t capture locals). The second is if the am does reference an instance member. The last is used if you reference/capture a local variable. There&#8217;s a great article on am here &#8211; <a href="http://www.theserverside.net/tt/articles/showarticle.tss?id=AnonymousMethods" rel="nofollow">http://www.theserverside.net/tt/articles/showarticle.tss?id=AnonymousMethods</a></p>
<p>So for anonymous methods, the first two would work fine since their declaring type is that of the defining or derived class. The last one would actually be a problem. Actually nested classes should have access to all members of the nesting class (even privates) so I have to make a change in the routine to allow for this. I&#8217;ll update the article.</p>
<p>With regards to delegates, I think it depends on how you mean. If you mean that someone calls the internal and protected member within the delegate callback then that method is the caller and the check would be ok. However, if you mean that the delegate&#8217;s target is the method that is doing the checking (the callee), then it may not work. If you do a begininvoke on the delegate (which results in it running in a separate thread), then it will result in an exception even if the begininvoke was initiated by the defining or derived class. That class won&#8217;t even be in the callstack when the delegate is invoked. However, I believe a direct invocation of the delegate should work. If you could give a specific example or examples, I&#8217;ll be sure to look into it more.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Smith</title>
		<link>http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-13</link>
		<dc:creator>Josh Smith</dc:creator>
		<pubDate>Sat, 15 Dec 2007 22:58:59 +0000</pubDate>
		<guid isPermaLink="false">http://agsmith.wordpress.com/2007/12/15/internal-and-protected-virtual/#comment-13</guid>
		<description>How does all this work if the &quot;internal AND protected&quot; method is called through a delegate or an anonymous method?</description>
		<content:encoded><![CDATA[<p>How does all this work if the &#8220;internal AND protected&#8221; method is called through a delegate or an anonymous method?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
