﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Omer van Kloeten commented on More generics gotchas, argh!</title><description>Should be "public class Foo&lt;TFromClass&gt; : IFoo&lt;TFromClass&gt; { }".
</description><link>http://ayende.com/2892/more-generics-gotchas-argh#comment5</link><guid>http://ayende.com/2892/more-generics-gotchas-argh#comment5</guid><pubDate>Tue, 23 Oct 2007 22:36:28 GMT</pubDate></item><item><title>Tim Scott commented on More generics gotchas, argh!</title><description>Incidentally, another way to make it pass is to specify any generic param:
  
  
Assert.AreEqual(typeof(IFoo&lt;Bar&gt;), typeof(Foo&lt;Bar&gt;).GetInterfaces()[0]);
  
or :
  
Assert.IsTrue(typeof(IFoo&lt;Bar&gt;).IsAssignableFrom(typeof(Foo&lt;Bar&gt;)));
</description><link>http://ayende.com/2892/more-generics-gotchas-argh#comment4</link><guid>http://ayende.com/2892/more-generics-gotchas-argh#comment4</guid><pubDate>Tue, 23 Oct 2007 20:25:25 GMT</pubDate></item><item><title>Ayende Rahien commented on More generics gotchas, argh!</title><description>Avish,
  
Yes, that was what I ended up doing. The problem is that it took me a long time to get to the point of "Oh, so _that_ is it"
</description><link>http://ayende.com/2892/more-generics-gotchas-argh#comment3</link><guid>http://ayende.com/2892/more-generics-gotchas-argh#comment3</guid><pubDate>Tue, 23 Oct 2007 19:22:52 GMT</pubDate></item><item><title>Avish commented on More generics gotchas, argh!</title><description>I was a little puzzled by it too on the first time, but when I ventured deeper into generics I realized this really is very logical. In fact, it wouldn't make sense any other way. 
  
  
See, when you say:
  
  
public class Foo&lt;T&gt; : IFoo&lt;T&gt;
  
  
The first &lt;T&gt; means "I'm declaring a generic parameter, let's call it T". But the second one means "Now I'm USING said generic parameter, in effect saying that any type constructed from Foo&lt;T&gt; will implement IFoo&lt;T&gt; *for the same T*." 
  
  
The fact that you used the same name (T) for the generic parameter declaration on IFoo is irrelevant; inside the scope of the generic class, T refers to the already-declared generic parameter. 
  
  
If IFoo&lt;T&gt; had IFoo&lt;&gt; in its interface map, nothing would work. That's more apparent when you consider stuff like "public class Thingy&lt;T&gt; : IFoo&lt;IEnumerable&lt;T&gt;&gt;". Here it's very obvious that you want the implemented interface to use the unbound generic parameter T, so that when you construct a concrete type out of that generic type, using System.Int32 for T, it'd implement IFoo&lt;IEnumerable&lt;int&gt;&gt;. . 
  
  
If that's any comfort, you can still do:
  
  
Assert.AreEqual(
  
    typeof(IFoo&lt;&gt;), 
  
    typeof(Foo&lt;&gt;).GetInterfaces()[0].GetGenericDefinition());
  
</description><link>http://ayende.com/2892/more-generics-gotchas-argh#comment2</link><guid>http://ayende.com/2892/more-generics-gotchas-argh#comment2</guid><pubDate>Tue, 23 Oct 2007 19:16:29 GMT</pubDate></item><item><title>JH commented on More generics gotchas, argh!</title><description>I've found this post to be quite helpful:
  
  
http://blogs.msdn.com/dinesh.kulkarni/archive/2005/09/09/463001.aspx
</description><link>http://ayende.com/2892/more-generics-gotchas-argh#comment1</link><guid>http://ayende.com/2892/more-generics-gotchas-argh#comment1</guid><pubDate>Tue, 23 Oct 2007 17:22:34 GMT</pubDate></item></channel></rss>