<?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: Checking Whether A Method Is Overridden</title> <atom:link href="http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Tue, 22 May 2012 17:40:00 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: Find, if a method is overridden in a derived class! &#171; ReflectWorks</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-101795</link> <dc:creator>Find, if a method is overridden in a derived class! &#171; ReflectWorks</dc:creator> <pubDate>Mon, 24 Oct 2011 08:16:07 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-101795</guid> <description>[...] I had a similar need, and built on top of what I found in the following implementation on http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/ [...]</description> <content:encoded><![CDATA[<p>[...] I had a similar need, and built on top of what I found in the following implementation on <a
href="http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/" rel="nofollow">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/</a> [...]</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-27200</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Wed, 03 Feb 2010 20:26:48 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-27200</guid> <description>@Dathanit&#039;s a tough one... if you derive from a request class, you&#039;re always going to add _something_ to it.  That &#039;something&#039; is pretty much always an important part of the value semantics of an instance of your request type, and as such it needs to be taken into account when doing the equality and hashcode checks in the context of cachingi&#039;m still not entirely sure on it though, which is why the check hasn&#039;t been committed to the project yet</description> <content:encoded><![CDATA[<p>@Dathan</p><p>it&#8217;s a tough one&#8230; if you derive from a request class, you&#8217;re always going to add _something_ to it.  That &#8216;something&#8217; is pretty much always an important part of the value semantics of an instance of your request type, and as such it needs to be taken into account when doing the equality and hashcode checks in the context of caching</p><p>i&#8217;m still not entirely sure on it though, which is why the check hasn&#8217;t been committed to the project yet</p> ]]></content:encoded> </item> <item><title>By: Dathan Bennett</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-27191</link> <dc:creator>Dathan Bennett</dc:creator> <pubDate>Wed, 03 Feb 2010 19:21:37 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-27191</guid> <description>&lt;blockquote cite=&quot;Davy Brion&quot;&gt;The only thing i’m forcing people to do is to make sure they have valid implementations of Equals and GetHashCode for _their_ situation and only if they want to use caching for that particular type of request.&lt;/blockquote&gt;To be precise, what your code here does is force the user to have an override of Equals and GetHashCode on &lt;em&gt;the most-derived class&lt;/em&gt;.  If they override on a base class and then inherit from it, their classes will fail your test, even though Equals and GetHashCode may be fully functional.  Is this the behavior you want?If not, Leon&#039;s approach should work better for you.</description> <content:encoded><![CDATA[<blockquote
cite="Davy Brion"><p>The only thing i’m forcing people to do is to make sure they have valid implementations of Equals and GetHashCode for _their_ situation and only if they want to use caching for that particular type of request.</p></blockquote><p>To be precise, what your code here does is force the user to have an override of Equals and GetHashCode on <em>the most-derived class</em>.  If they override on a base class and then inherit from it, their classes will fail your test, even though Equals and GetHashCode may be fully functional.  Is this the behavior you want?</p><p>If not, Leon&#8217;s approach should work better for you.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24763</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Wed, 13 Jan 2010 07:45:25 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24763</guid> <description>@Victoryou do have to put an attribute on top of your request class to enable caching for it so there is some kind of explicitness (though not entirely obviously), response types don&#039;t need to be altered in any way though.The only thing i&#039;m forcing people to do is to make sure they have valid implementations of Equals and GetHashCode for _their_ situation and only if they want to use caching for that particular type of request. I agree that it&#039;s not ideal, but it&#039;s the only way i could come up with to make it work.</description> <content:encoded><![CDATA[<p>@Victor</p><p>you do have to put an attribute on top of your request class to enable caching for it so there is some kind of explicitness (though not entirely obviously), response types don&#8217;t need to be altered in any way though.</p><p>The only thing i&#8217;m forcing people to do is to make sure they have valid implementations of Equals and GetHashCode for _their_ situation and only if they want to use caching for that particular type of request. I agree that it&#8217;s not ideal, but it&#8217;s the only way i could come up with to make it work.</p> ]]></content:encoded> </item> <item><title>By: Victor Kornov</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24732</link> <dc:creator>Victor Kornov</dc:creator> <pubDate>Wed, 13 Jan 2010 01:29:09 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24732</guid> <description>Yeah, sorry, I wan&#039;t clear. What I really meant is... you could require this interface to be implemented to make caching more explicit. It already requires modification of the response classes. Adding an interface like that should make people think of what they are doing. In any case, you can&#039;t do much about this whole thing. This is exactly like the case with .NET in-built hashes\dictionaries. You just have to remember.Btw, how this &quot;check if Equals&amp;GetHashCode are overridden&quot; thing is going to work with a case of base class implementing those 2 methods? You pretty much force people to have redundant, &quot;base&quot; forwarding implementations then.</description> <content:encoded><![CDATA[<p>Yeah, sorry, I wan&#8217;t clear. What I really meant is&#8230; you could require this interface to be implemented to make caching more explicit. It already requires modification of the response classes. Adding an interface like that should make people think of what they are doing. In any case, you can&#8217;t do much about this whole thing. This is exactly like the case with .NET in-built hashes\dictionaries. You just have to remember.</p><p>Btw, how this &#8220;check if Equals&amp;GetHashCode are overridden&#8221; thing is going to work with a case of base class implementing those 2 methods? You pretty much force people to have redundant, &#8220;base&#8221; forwarding implementations then.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24666</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Tue, 12 Jan 2010 14:35:56 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24666</guid> <description>@VictorYeah, but like Steve said it wouldn&#039;t help :)</description> <content:encoded><![CDATA[<p>@Victor</p><p>Yeah, but like Steve said it wouldn&#8217;t help <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Steve</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24654</link> <dc:creator>Steve</dc:creator> <pubDate>Tue, 12 Jan 2010 13:22:54 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24654</guid> <description>@VictorThat won&#039;t help since System.Object already implements those methods.</description> <content:encoded><![CDATA[<p>@Victor</p><p>That won&#8217;t help since System.Object already implements those methods.</p> ]]></content:encoded> </item> <item><title>By: Victor Kornov</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24651</link> <dc:creator>Victor Kornov</dc:creator> <pubDate>Tue, 12 Jan 2010 13:08:03 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24651</guid> <description>Did you consider a role interface like ICacheable { bool Equals(); int GetHashCode();} which all cached responses must implement?</description> <content:encoded><![CDATA[<p>Did you consider a role interface like ICacheable { bool Equals(); int GetHashCode();} which all cached responses must implement?</p> ]]></content:encoded> </item> <item><title>By: The Morning Brew - Chris Alcock &#187; The Morning Brew #515</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24618</link> <dc:creator>The Morning Brew - Chris Alcock &#187; The Morning Brew #515</dc:creator> <pubDate>Tue, 12 Jan 2010 08:47:42 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24618</guid> <description>[...] Checking Whether A Method Is Overridden - Davy Brion shows a technique you can use to detect if the implementation of a method has been overridden in the type you are calling it on. [...]</description> <content:encoded><![CDATA[<p>[...] Checking Whether A Method Is Overridden &#8211; Davy Brion shows a technique you can use to detect if the implementation of a method has been overridden in the type you are calling it on. [...]</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24617</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Tue, 12 Jan 2010 07:45:18 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24617</guid> <description>@Leongreat stuff, didn&#039;t know about that :)</description> <content:encoded><![CDATA[<p>@Leon</p><p>great stuff, didn&#8217;t know about that <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Dave H</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24567</link> <dc:creator>Dave H</dc:creator> <pubDate>Tue, 12 Jan 2010 01:04:39 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24567</guid> <description>Thanks for posting about this, I have a similar check in a unit test for a company project to make sure people obey our domain object contract when they make new objects. It saves a lot of debugging headaches!</description> <content:encoded><![CDATA[<p>Thanks for posting about this, I have a similar check in a unit test for a company project to make sure people obey our domain object contract when they make new objects. It saves a lot of debugging headaches!</p> ]]></content:encoded> </item> <item><title>By: Leon Breedt</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24553</link> <dc:creator>Leon Breedt</dc:creator> <pubDate>Mon, 11 Jan 2010 23:12:37 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24553</guid> <description>If it wasn&#039;t clear, checking for virtual and reuse-slot pretty much verifies that the method was declared thus:\override RETURN-Type MethodName(...)\At least from my understanding :)</description> <content:encoded><![CDATA[<p>If it wasn&#8217;t clear, checking for virtual and reuse-slot pretty much verifies that the method was declared thus:</p><p>\override RETURN-Type MethodName(&#8230;)\</p><p>At least from my understanding <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Leon Breedt</title><link>http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/comment-page-1/#comment-24551</link> <dc:creator>Leon Breedt</dc:creator> <pubDate>Mon, 11 Jan 2010 23:10:37 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/01/checking-whether-a-method-is-overridden/#comment-24551</guid> <description>A little more robust: Check for Virtual and the presence of the ReuseSlot flag.static bool IsMethodOverriden(Type type, string methodName)
{
var mi = type.GetMethod(methodName, BindingFlags.Instance &#124; BindingFlags.Public &#124; BindingFlags.DeclaredOnly);
return ((mi.Attributes &amp; MethodAttributes.Virtual) != 0) &amp;&amp;
((mi.Attributes &amp; MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot);
}Also, for your use case, I believe you want to include BindingFlags.DeclaredOnly, so that it doesn&#039;t search up the hierarchy, but maybe not...</description> <content:encoded><![CDATA[<p>A little more robust: Check for Virtual and the presence of the ReuseSlot flag.</p><p> static bool IsMethodOverriden(Type type, string methodName)<br
/> {<br
/> var mi = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);<br
/> return ((mi.Attributes &amp; MethodAttributes.Virtual) != 0) &amp;&amp;<br
/> ((mi.Attributes &amp; MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot);<br
/> }</p><p>Also, for your use case, I believe you want to include BindingFlags.DeclaredOnly, so that it doesn&#8217;t search up the hierarchy, but maybe not&#8230;</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/17 queries in 0.008 seconds using disk: basic
Object Caching 533/534 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-05-23 02:19:31 -->
