title: Covariance in C# generic class
body: <p>C# 4.0 .NET 4.5 Silverlight 5
  It seems weird that I cant find the solution so need some help please.</p>
  
  <p>I have base class Base and derived class Child : Base. I have also helper class which has generic type to do specific work one EF entities Helper where T : EntityObject.</p>
  
  <p>Child does specific work with a specific entity MyEntity : EntityObject.</p>
  
  <p>So I tried:</p>
  
  <pre><code>public class Base
  {
      protected Helper&lt;EntityObject&gt; helper;
  }
  public class Child : Base
  {
      public Child()
      {
          helper = new Helper&lt;MyEntity&gt;();
      }
  }
  </code></pre>
  
  <p>I would expect that more derived class must know about more specific generic parameter and I think that's what covariance for... But that doesn't work...</p>
  
  <p>What's the 'correct' way to design class like that?</p>
  
  <p><strong>EDIT:</strong> sorry I didn't make it 100% clear why cant I achieve what I need.</p>
  
  <p><strong>a. Solution with generic Base</strong> doesn't work because user of the Base doesn't know the T type. Imagine:</p>
  
  <pre><code>public class User
  {
      private Base&lt;T&gt; base; // this will not compile.
      public User(TypeEnum t)
      {
          if(t == TypeEnum.MyEntity) base = new Child();
  ...
  </code></pre>
  
  <p><strong>b. Solution with Interface</strong> doesn't work because helper uses T everywhere (it is its purpose right?). Imagine it has method </p>
  
  <pre><code>public IEnumerable&lt;T&gt; Process(IEnumerable&lt;T&gt; items) { return items; }
  </code></pre>
  
  <p>How do I bring it up in the interface which doesn't know anything about T</p>