<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx</link><description>By now, you’ve probably heard that C# 4.0 is adding support for the dynamic keyword, which introduces some aspects of dynamic languages to C#.&amp;#160; I had not had a chance to really try it, but recently I was reading Bertrand Le Roy’s post on the topic</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#10156846</link><pubDate>Thu, 21 Apr 2011 20:49:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10156846</guid><dc:creator>Gregory Chernis</dc:creator><description>&lt;p&gt;With some help, worked out a way to access the constant fields too:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://stackoverflow.com/questions/5749396/accessing-constants-with-a-dynamic-keyword"&gt;stackoverflow.com/.../accessing-constants-with-a-dynamic-keyword&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10156846" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#10060447</link><pubDate>Fri, 10 Sep 2010 19:36:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10060447</guid><dc:creator>Omer Raviv</dc:creator><description>&lt;p&gt;This could&amp;#39;ve been great for the various .Parse method overloads that the primitive BCL types provide (The Convert class doesn&amp;#39;t solve everything.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10060447" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#9946150</link><pubDate>Sat, 09 Jan 2010 19:17:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9946150</guid><dc:creator>David Ebbo</dc:creator><description>&lt;p&gt;@Stephen: agreed, that's a nice little addition.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9946150" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#9946149</link><pubDate>Sat, 09 Jan 2010 19:07:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9946149</guid><dc:creator>Stephen Swensen</dc:creator><description>&lt;p&gt;Thanks for this. &amp;nbsp;You can take it a step further with extension methods:&lt;/p&gt;
&lt;p&gt;&amp;lt;code&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;static readonly Dictionary&amp;lt;Type, StaticMembersDynamicWrapper&amp;gt; _typeLookup = new Dictionary&amp;lt;Type, StaticMembersDynamicWrapper&amp;gt;();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static dynamic StaticMembersProxy(this Type type)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;StaticMembersDynamicWrapper smdw;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (!_typeLookup.TryGetValue(type, out smdw))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_typeLookup[type] = smdw = new StaticMembersDynamicWrapper(type);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return smdw;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;lt;/code&amp;gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9946149" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#9927107</link><pubDate>Mon, 23 Nov 2009 05:44:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9927107</guid><dc:creator>Paul Batum</dc:creator><description>&lt;p&gt;This is a nice in that it is an easy to follow example of using the DynamicObject class, but...&lt;/p&gt;
&lt;p&gt;Even in the case where you are forced to rely on 3rd party libraries that are exposing the functionality you need as static methods, you should be able to wrap that functionality inside your own classes and then have them implement a common interface. Therefore I am skeptical about whether the above approach is actually something you would ever want to do.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9927107" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#9916876</link><pubDate>Tue, 03 Nov 2009 18:11:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9916876</guid><dc:creator>David Ebbo</dc:creator><description>&lt;p&gt;@David Kujawski: indeed, my code above is just a proof of concept and doesn't deal with cases like method overloading. &amp;nbsp;Thanks for pointing this out!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9916876" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#9916846</link><pubDate>Tue, 03 Nov 2009 17:07:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9916846</guid><dc:creator>David Kujawski</dc:creator><description>&lt;p&gt;Nice work, this is useful, however there are two problems with your approach:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; 1) no handling of overloaded methods&lt;/p&gt;
&lt;p&gt; &amp;nbsp; 2) incorrect handling of optional/named parameters&lt;/p&gt;
&lt;p&gt;I can't post the code here (in the comments since it would look terrible), but I was able modify the code to check the Binder and get the Parameters for the methods of the type to correctly handle the two issues above.&lt;/p&gt;
&lt;p&gt;Thanks for the headstart!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9916846" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#9913118</link><pubDate>Mon, 26 Oct 2009 19:26:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9913118</guid><dc:creator>David Ebbo</dc:creator><description>&lt;p&gt;@J&amp;#233;r&amp;#233;mie: the idea of static interfaces is potentially interesting. &amp;nbsp;One different is that in your case, you have T has a generic type param (as in IsInstanciated&amp;lt;T&amp;gt;() where T: ICountable). But how would you 'cast' to this interface if all you had was a System.Type, in a really late bound scenario?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9913118" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#9913023</link><pubDate>Mon, 26 Oct 2009 16:41:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9913023</guid><dc:creator>WebGrid</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It's like Jayson says it's nice for &amp;quot;duct-taping&amp;quot; 3rd party libraries.&lt;/p&gt;
&lt;p&gt;It saved my day! :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9913023" width="1" height="1"&gt;</description></item><item><title>re: Using C# dynamic to call static members</title><link>http://blogs.msdn.com/b/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx#9912987</link><pubDate>Mon, 26 Oct 2009 15:52:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9912987</guid><dc:creator>Jérémie Chassaing</dc:creator><description>&lt;p&gt;Coincidence, three days ago I posted a 'proposal' (nothing official here...) for static interface to resolve this kind of thing in C#.&lt;/p&gt;
&lt;p&gt;You can read it here : &lt;a rel="nofollow" target="_new" href="http://thinkbeforecoding.com/post/2009/10/21/CSharp-Static-interfaces"&gt;http://thinkbeforecoding.com/post/2009/10/21/CSharp-Static-interfaces&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;and here&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://thinkbeforecoding.com/post/2009/10/22/CSharp-Static-interfaces-Take-2"&gt;http://thinkbeforecoding.com/post/2009/10/22/CSharp-Static-interfaces-Take-2&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9912987" width="1" height="1"&gt;</description></item></channel></rss>