<?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: Fun with C# generics: down-casting to a generic type</title>
	<atom:link href="http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/feed/" rel="self" type="application/rss+xml" />
	<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/</link>
	<description>On programming, technology, and random things of interest</description>
	<lastBuildDate>Thu, 29 Jul 2010 00:28:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Andrew Borodin</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-978</link>
		<dc:creator>Andrew Borodin</dc:creator>
		<pubDate>Sun, 30 May 2010 12:09:14 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-978</guid>
		<description>Usefulll casting, btw. Thx (:</description>
		<content:encoded><![CDATA[<p>Usefulll casting, btw. Thx (:</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Borodin</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-977</link>
		<dc:creator>Andrew Borodin</dc:creator>
		<pubDate>Sun, 30 May 2010 12:05:28 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-977</guid>
		<description>Small typo
public override Pair ConstructPair(Node secondNode) {
		return &lt;b&gt;other&lt;/b&gt;.ConstructPair(this);
	}</description>
		<content:encoded><![CDATA[<p>Small typo<br />
public override Pair ConstructPair(Node secondNode) {<br />
		return <b>other</b>.ConstructPair(this);<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MASHA</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-877</link>
		<dc:creator>MASHA</dc:creator>
		<pubDate>Mon, 19 Apr 2010 18:57:47 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-877</guid>
		<description>Ok i see...but it wasnt tags ) last one

i just ment that when return new Pair i am to use type not TFirst, but (i&#039;ve just called it not to have Classes with the same names, so i have not Node and Node&#039;T&#039; but Node and TypedNode&#039;T&#039;)
TypedNode&#039;TFirst&#039; and TypedNode&#039;T&#039; instead of just &#039;T&#039;.

ps why skipping text in angular brackets...</description>
		<content:encoded><![CDATA[<p>Ok i see&#8230;but it wasnt tags ) last one</p>
<p>i just ment that when return new Pair i am to use type not TFirst, but (i&#8217;ve just called it not to have Classes with the same names, so i have not Node and Node&#8217;T&#8217; but Node and TypedNode&#8217;T')<br />
TypedNode&#8217;TFirst&#8217; and TypedNode&#8217;T&#8217; instead of just &#8216;T&#8217;.</p>
<p>ps why skipping text in angular brackets&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MASHA</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-876</link>
		<dc:creator>MASHA</dc:creator>
		<pubDate>Mon, 19 Apr 2010 18:45:02 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-876</guid>
		<description>Hmmmm...
Why did browser skipped my post in thi strange way ?
Ok, i just ment that when return new Pair i am to use type not TFirst, but (i&#039;ve just called it not to have Classes with the same names, so i have not Node and Node but Node and TypedNode)
TypedNode and TypedNode instead of just .
Thats all)
ps Fix this browser&#039;s strange behavior!)</description>
		<content:encoded><![CDATA[<p>Hmmmm&#8230;<br />
Why did browser skipped my post in thi strange way ?<br />
Ok, i just ment that when return new Pair i am to use type not TFirst, but (i&#8217;ve just called it not to have Classes with the same names, so i have not Node and Node but Node and TypedNode)<br />
TypedNode and TypedNode instead of just .<br />
Thats all)<br />
ps Fix this browser&#8217;s strange behavior!)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MASHA</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-875</link>
		<dc:creator>MASHA</dc:creator>
		<pubDate>Mon, 19 Apr 2010 18:33:38 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-875</guid>
		<description>Hi there!
Good idea. But ...I still had compilation error untill changed this:
 return new Pair&lt;TypedNode, TypedNode&gt;(firstNode, this);
 Anyway, I solved my problem, so thanks! :-)</description>
		<content:encoded><![CDATA[<p>Hi there!<br />
Good idea. But &#8230;I still had compilation error untill changed this:<br />
 return new Pair&lt;TypedNode, TypedNode&gt;(firstNode, this);<br />
 Anyway, I solved my problem, so thanks! <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wigy</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-706</link>
		<dc:creator>Wigy</dc:creator>
		<pubDate>Mon, 15 Feb 2010 21:36:57 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-706</guid>
		<description>I am just catching up with your blog, Igor. Congrats, you have great content.

The problem you described here is quite interesting. Having a heterogeneous collection like your linked list and depending on the type of &lt;em&gt;2&lt;/em&gt; elements is not trivial.

Knowing you have a single algorithm (building pairs) and that you have only a single generic class that implements the Node interface, it is quite elegant to just ask the abstract Node class for some help. This way you could avoid implementing a 3-way dispatch by generalizing the &lt;a href=&quot;http://en.wikipedia.org/wiki/Visitor_pattern&quot; rel=&quot;nofollow&quot;&gt;visitor pattern&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>I am just catching up with your blog, Igor. Congrats, you have great content.</p>
<p>The problem you described here is quite interesting. Having a heterogeneous collection like your linked list and depending on the type of <em>2</em> elements is not trivial.</p>
<p>Knowing you have a single algorithm (building pairs) and that you have only a single generic class that implements the Node interface, it is quite elegant to just ask the abstract Node class for some help. This way you could avoid implementing a 3-way dispatch by generalizing the <a href="http://en.wikipedia.org/wiki/Visitor_pattern" rel="nofollow">visitor pattern</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-572</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Wed, 09 Sep 2009 19:28:59 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-572</guid>
		<description>You can get on the data in solution #3... that&#039;s actually the point. The trick is to add a virtual method DoSomething on the non-generic Node class, and then override it in the Node&lt;T&gt; generic class. In DoSomething in the derived generic class, you can access T (the data) in a type-safe way.

My approach #3 requires that you are able to add a method to the Node class. If you can&#039;t do that, use approach #2. See my explanation to orastem for some details on how to do that.</description>
		<content:encoded><![CDATA[<p>You can get on the data in solution #3&#8230; that&#8217;s actually the point. The trick is to add a virtual method DoSomething on the non-generic Node class, and then override it in the Node&lt;T&gt; generic class. In DoSomething in the derived generic class, you can access T (the data) in a type-safe way.</p>
<p>My approach #3 requires that you are able to add a method to the Node class. If you can&#8217;t do that, use approach #2. See my explanation to orastem for some details on how to do that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-571</link>
		<dc:creator>Chad</dc:creator>
		<pubDate>Wed, 09 Sep 2009 19:18:19 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-571</guid>
		<description>Thanks.  Follow-up: when operating on your tree of nodes, did you ever need to get to the Data?  Seems like the only way to get at the Data would be your Solution #1.

Context of my question: If your nodes were stored in a DB, and you wanted to expose them to a consumer, as some kind of generic collection, the collection would have to be typed to the abstract class, and the consumer would have to down-cast the nodes in order to get to the Data.  I think similar to your solution #1.

Do you have a solution for getting at the data more along the lines of your Solution #3?</description>
		<content:encoded><![CDATA[<p>Thanks.  Follow-up: when operating on your tree of nodes, did you ever need to get to the Data?  Seems like the only way to get at the Data would be your Solution #1.</p>
<p>Context of my question: If your nodes were stored in a DB, and you wanted to expose them to a consumer, as some kind of generic collection, the collection would have to be typed to the abstract class, and the consumer would have to down-cast the nodes in order to get to the Data.  I think similar to your solution #1.</p>
<p>Do you have a solution for getting at the data more along the lines of your Solution #3?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-570</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Wed, 09 Sep 2009 19:01:20 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-570</guid>
		<description>Chad:

Yes, you could have a list of non-generic nodes. In the scenario I encountered, I actually had a tree of them.</description>
		<content:encoded><![CDATA[<p>Chad:</p>
<p>Yes, you could have a list of non-generic nodes. In the scenario I encountered, I actually had a tree of them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad</title>
		<link>http://igoro.com/archive/fun-with-c-generics-down-casting-to-a-generic-type/comment-page-1/#comment-569</link>
		<dc:creator>Chad</dc:creator>
		<pubDate>Wed, 09 Sep 2009 18:50:22 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/?p=22#comment-569</guid>
		<description>Very nice. I am still trying to get a feel for generic classes, so excuse the ignorance.

Is one of the reasons for the abstract Node so that you can consume a generic list of nodes: List myModes;

And it would be on the consumer to check the type of of the individual concrete nodes in the list?</description>
		<content:encoded><![CDATA[<p>Very nice. I am still trying to get a feel for generic classes, so excuse the ignorance.</p>
<p>Is one of the reasons for the abstract Node so that you can consume a generic list of nodes: List myModes;</p>
<p>And it would be on the consumer to check the type of of the individual concrete nodes in the list?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
