title: Generic interface implementation: Generic return type and generic input type
body: <p>I want to create class system to generalize getting and posting data from some data source. I have two methods: GetData and PostData. Both methods should have some kind of input, and GetData should also have return type. I tried to write generic interface and to implement it in "DatabaseSource" class:</p>
  
  <pre><code>public class QueryParameter
  {
      public QueryParameter()
      {
          this.Direction = ParameterDirection.Input;
      }
  
      public string Name { get; set; }
      public object Value { get; set; }
      public ParameterDirection Direction { get; set; }
  }
  
  public class InputBase
  {
      public InputBase()
      {
          ResultMapping = new Dictionary&lt;string, string&gt;();
          Parameters = new List&lt;QueryParameter&gt;();
      }
      public Dictionary&lt;string, string&gt; ResultMapping { get; set; }
      public List&lt;QueryParameter&gt; Parameters { get; set; }
  }
  public class DatabaseInput: InputBase
      {
          public string Query { get; set; }
          public DatabaseCommandType CommandType { get; set; }
      }
  
  public interface IDataSource&lt;I&gt; where I: InputBase
  {
      IEnumerable&lt;T&gt; GetData&lt;T&gt;(I input);
      void PostData(I Input);
  } 
  </code></pre>
  
  <p>Now i tried to implement interface like this:</p>
  
  <pre><code>public class DatabaseDataSource: IDataSource&lt;DatabaseInput&gt;
  {
      public IEnumerable&lt;T&gt; GetData&lt;T&gt;(DatabaseInput Input)
      {
          //implementation
      }
  
      public void PostData(DatabaseInput Input)
      {
          //implementation
      }
  }
  </code></pre>
  
  <p>But i have a problem when I try to instantiate data source like this:</p>
  
  <pre><code>IDataSource&lt;InputBase&gt; dataSource = new DatabaseDataSource();
  </code></pre>
  
  <p>I cannot use DatabaseInput because this code is in some kind of factory method and I should be able to instantiate other IDataSource implementations.</p>
  
  <p>In short I want to have Input and Output as generic types, and to constraint Input to match concrete IDataSource implementation.</p>