<?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>Generic Methods as Casts</title><link>http://blogs.msdn.com/kcwalina/archive/2007/06/07/GenericMethodsAsCasts.aspx</link><description>Somebody just asked me which of the following API design alternatives is better. They both do what we could call “casting.” // Generic Method “Cast” var foo = someInstance.SomeMethod&amp;lt;IFoo&amp;gt;(); // Simple Cast var foo = (IFoo) someInstance.SomeMethod();</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Generic Methods as Casts</title><link>http://blogs.msdn.com/kcwalina/archive/2007/06/07/GenericMethodsAsCasts.aspx#3147995</link><pubDate>Thu, 07 Jun 2007 23:31:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3147995</guid><dc:creator>Tom Kirby-Green</dc:creator><description>&lt;p&gt;Hi Krzysztof,&lt;/p&gt;
&lt;p&gt;Do you and Brad plan to write an updated edition of the Framework Class Guidelines? I was wondering if you chaps planned covering designing types for more declarative APIs (i.e. XAML bindings), designing types to enable rich and efficient LINQ to Object queries and maybe designing types to support a more functional style of programming.&lt;/p&gt;
&lt;p&gt;Or maybe none of these but something different. Do you envisage a new edition of the book any time?&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;tom&lt;/p&gt;</description></item><item><title>re: Generic Methods as Casts</title><link>http://blogs.msdn.com/kcwalina/archive/2007/06/07/GenericMethodsAsCasts.aspx#3151811</link><pubDate>Fri, 08 Jun 2007 03:58:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3151811</guid><dc:creator>IDisposable</dc:creator><description>&lt;p&gt;Another nice feature of doing it with a generic is that sometimes the type can be inferred. &amp;nbsp;My personal favorite example is:&lt;/p&gt;
&lt;p&gt;public object GetValue(string key, object defaultValue)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; if (this.Values.Contains(key))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; return this.Values[key];&lt;/p&gt;
&lt;p&gt; &amp;nbsp; else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; return defaultValue;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;// call like this...&lt;/p&gt;
&lt;p&gt;int x = (int)configuration.GetValue(&amp;quot;X&amp;quot;, 0);&lt;/p&gt;
&lt;p&gt;Can turn into:&lt;/p&gt;
&lt;p&gt;public T GetValue&amp;lt;T&amp;gt;(string key, T defaultValue)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; if (this.Values.Contains(key))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; return (T)this.Values[key];&lt;/p&gt;
&lt;p&gt; &amp;nbsp; else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; return defaultValue;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;// call like this...&lt;/p&gt;
&lt;p&gt;int x = configuration.GetValue&amp;lt;int&amp;gt;(&amp;quot;X&amp;quot;, 0);&lt;/p&gt;
&lt;p&gt;// or even cooler, like this...&lt;/p&gt;
&lt;p&gt;double z = configuration.GetValue(&amp;quot;Z&amp;quot;, 0.0);&lt;/p&gt;
&lt;p&gt;That's the cool bit...&lt;/p&gt;</description></item><item><title>re: Generic Methods as Casts</title><link>http://blogs.msdn.com/kcwalina/archive/2007/06/07/GenericMethodsAsCasts.aspx#3235057</link><pubDate>Mon, 11 Jun 2007 23:27:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3235057</guid><dc:creator>kcwalina</dc:creator><description>&lt;p&gt;Tom, we are thinking about updating the guidelines with C# 3.0 and Framework 2.0+ things. We just don't yet have concrete plans. I am starting to draft guidelines (as we speak) and I will post them to the blog. At some point, I will try to fold them into the book.&lt;/p&gt;
</description></item></channel></rss>