<?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>More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx</link><description>Here are some more unsorted thoughts on generics to continue this post (which has some interesting comments too). Preserving types with generic type inference To reiterate, instead of having a method like: void Process( object instance) { } one can write:</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#8952546</link><pubDate>Mon, 15 Sep 2008 16:31:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8952546</guid><dc:creator>Jon Skeet</dc:creator><description>&lt;p&gt;Firstly, thanks for the book plug - it's always nice to get a mention :)&lt;/p&gt;
&lt;p&gt;It sounds like we've been running into similar (but not the same) restrictions in .NET/C# around generics. I blogged my findings when porting Protocol Buffers recently - any comments would be welcome.&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msmvps.com/blogs/jon_skeet/archive/tags/Protocol+Buffers/default.aspx"&gt;http://msmvps.com/blogs/jon_skeet/archive/tags/Protocol+Buffers/default.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Jon&lt;/p&gt;
</description></item><item><title>re: More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#8960706</link><pubDate>Mon, 22 Sep 2008 00:58:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8960706</guid><dc:creator>Brennan Falkner</dc:creator><description>&lt;p&gt;class Blah : IDependencyNode&amp;lt;Figure, OtherList&amp;gt;, IDependencyNode&amp;lt;Blah, AnotherList&amp;gt; { }&lt;/p&gt;
&lt;p&gt;class AnotherList : List&amp;lt;Figure&amp;gt;, IDependencyList&amp;lt;Figure&amp;gt;, IDependencyList&amp;lt;Blah&amp;gt; { }&lt;/p&gt;
&lt;p&gt;So yeah, I was just thinking about how painful it would be to have to figure out that algorithm.&lt;/p&gt;
&lt;p&gt;May I suggest to you..?&lt;/p&gt;
&lt;p&gt;using System.Collections.Generic;&lt;/p&gt;
&lt;p&gt;interface IDependencyNode&amp;lt;TNode&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;where TNode : IDependencyNode&amp;lt;TNode&amp;gt;&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;// IEnumerable&amp;lt;TNode&amp;gt; Dependencies { get; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;static class Extensions&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public static IEnumerable&amp;lt;TNode&amp;gt; TopologicalSort&amp;lt;TNode&amp;gt;(this IEnumerable&amp;lt;TNode&amp;gt; nodes)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where TNode : IDependencyNode&amp;lt;TNode&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return null; // algorithm goes here&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;class Figure : IDependencyNode&amp;lt;Figure&amp;gt; { }&lt;/p&gt;
&lt;p&gt;class Program&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static void Main(string[] args)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;List&amp;lt;Figure&amp;gt; list = new List&amp;lt;Figure&amp;gt;();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;list.TopologicalSort(); // compiles fine&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item><item><title>re: More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#8960846</link><pubDate>Mon, 22 Sep 2008 06:50:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8960846</guid><dc:creator>Kirill Osenkov</dc:creator><description>&lt;p&gt;Ha-ha, Brennan, you almost make me feel like I'm an architectural astronaut :)&lt;/p&gt;
&lt;p&gt;This chunk of code was to demonstrate a limitation of the C# 3.0 type inference engine, and thankfully doesn't come from production code. Also the last paragraph of my post is there on purpose too.&lt;/p&gt;
&lt;p&gt;Jon: great blog posts! I've forwarded a link to Mads Torgersen.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description></item><item><title>Comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#8968378</link><pubDate>Mon, 29 Sep 2008 05:50:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8968378</guid><dc:creator>Riaan's Blog</dc:creator><description>&lt;p&gt;Some good tips on using Genetics &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments"&gt;http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Kirill Osenkov : More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#8971412</link><pubDate>Wed, 01 Oct 2008 13:52:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8971412</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
</description></item><item><title>re: More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#8973129</link><pubDate>Thu, 02 Oct 2008 11:13:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8973129</guid><dc:creator>John Rusk</dc:creator><description>&lt;p&gt;Your technique of Process&amp;lt;T&amp;gt;(T instance) plays nicely with extension methods:&lt;/p&gt;
&lt;p&gt;E.g. you can write &amp;nbsp;&lt;/p&gt;
&lt;p&gt;T Process&amp;lt;T&amp;gt;(this T instance) where T ....&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;// do stuff...&lt;/p&gt;
&lt;p&gt; &amp;nbsp;return instance;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;to get a method which you can call on any T and which will return a strongly typed T. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;This can come in handy in fluent APIs, when you want a method that can act on a range of classes in the API, but for which the implementation is the same and the only difference is the strong return type.&lt;/p&gt;
</description></item><item><title>re: More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#8997681</link><pubDate>Mon, 13 Oct 2008 12:30:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8997681</guid><dc:creator>Aridane Álamo</dc:creator><description>&lt;p&gt;Nice article, thanks.&lt;/p&gt;
&lt;p&gt;Just one more question, there is anyway to define the base type of a generic in a method?&lt;/p&gt;
&lt;p&gt;Something like&lt;/p&gt;
&lt;p&gt;public void Update&amp;lt;T&amp;gt;() where T:DataSet {}&lt;/p&gt;
</description></item><item><title>re: More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#9012232</link><pubDate>Thu, 23 Oct 2008 05:41:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9012232</guid><dc:creator>Kirill Osenkov</dc:creator><description>&lt;p&gt;Aridane: yes, it is called Generic Constraints (&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/d5x73970"&gt;http://msdn.microsoft.com/en-us/library/d5x73970&lt;/a&gt;(VS.80).aspx) and can be used exactly as you typed.&lt;/p&gt;
</description></item><item><title>re: More comments on generics</title><link>http://blogs.msdn.com/kirillosenkov/archive/2008/09/15/more-comments-on-generics.aspx#9439261</link><pubDate>Sun, 22 Feb 2009 08:47:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9439261</guid><dc:creator>Shalabh Gupta</dc:creator><description>&lt;p&gt;Amazing Article. Thanks for such a valuable info..&lt;/p&gt;
</description></item></channel></rss>