title: C# Interface<T> { T Func<T>(T t);} : Generic Interfaces with Parameterized Methods with Generic Return Types
body: <p>I thought I'd use some (what I thought was) simple generics to enforce CRUD on some Business Classes.
  eg. </p>
  
  <pre><code>public interface IReadable &lt;T&gt;
  {
      T Read&lt;T&gt;(string ID);
  }
  </code></pre>
  
  <p>and then perhaps, I could have a NoteAdapter to do C<strong>R</strong>UD with the Note class eg.</p>
  
  <pre><code>public class NoteAdapter : IReadable&lt;Note&gt;
  {
      public Note Read&lt;Note&gt;(string ID) {
          return new Note();
      }
  }
  </code></pre>
  
  <p>But for some reason, te compiler is getting confused if I have both a generic return Type and a function Parameterized with the same generic Type. That is , if I do :</p>
  
  <pre><code>public interface IReadable &lt;T&gt;
  {
      void Read&lt;T&gt;(string ID);
  }
  public class NoteAdapter : IReadable&lt;Note&gt;
  {
      public void Read&lt;Note&gt;(string ID) {
          return new Note();
      }
  }
  </code></pre>
  
  <p>It compiles fine, although it doesnt do what I want it to !
  Also, this :</p>
  
  <pre><code>public interface IReadable &lt;T&gt;
  {
      T Read (string ID);
  }
  public class NoteAdapter : IReadable&lt;Note&gt;
  {
      public Note Read(string ID) {
          return new Note();
      }
  }
  </code></pre>
  
  <p>works fine as well, <strong>Although it too does not satisfy the requirements</strong> ! -- Why ?
  Because then I can't have one Class that implements a bunch of these Interfaces ..eg.</p>
  
  <pre><code>public interface IReadable &lt;T&gt;{
      T Read (string ID);
  }
  public class UniversalAdapter : IReadable&lt;Note&gt;, IReadable&lt;Customer&gt; ...
  {
      public Note Read(string ID) {
          return new Note();
      }
      public Customer Read(string ID) {
          return new Customer();
      }
  }
  </code></pre>
  
  <p>Coz this would not compile as return types are not part of the methods signature !</p>
  
  <p>I was under the impression, in C# 3.5 + </p>
  
  <pre><code>T Foo(T t);
  T Foo&lt;T&gt; (T t);
  T Foo(&lt;SomeType&gt; someInstance);
  </code></pre>
  
  <p>All have different signatures! What am I missing here ? </p>