title: Creating a virtual generic method in C#
body: <p>I have some base classes like this:</p>
  
  <pre><code>public class AbstractData
  {
      public int ID { get; set; }
  }
  
  public class Person: AbstractData
  {
      public string Name { get; set; }
  }
  
  public class AbstractManager&lt;T&gt; where T: AbstractData
  {
      public virtual List&lt;T&gt; GetAll()
      {
      }
  
      public virtual T GetOne(int id)
      {
      }
  }
  
  public class PersonManager: AbstractManager&lt;Person&gt;
  {
      public override List&lt;Person&gt; GetAll()
      {
          //...
      }
  
      public override Person GetOne(int id)
      {
          //...
      }
  }
  </code></pre>
  
  <p>Now, I have a Windows Forms base class, like this:</p>
  
  <pre><code>public class BaseForm: Form
  {
      public virtual AbstractManager&lt;T&gt; GetManager&lt;T&gt;() where T: AbstractData
      {
          return null;
      }
  }
  </code></pre>
  
  <p>and a derived form:</p>
  
  <pre><code>public class PersonForm: BaseForm
  {
      public override AbstractManager&lt;T&gt; GetManager&lt;T&gt;()
      {
          return new PersonManager();
      }
  }
  </code></pre>
  
  <p>The problem is, I keep getting compile errors on the PersonForm class:</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'PersonManager' to 'AbstractManager&lt;T&gt;'</p>
  </blockquote>
  
  <p>Is there a way in which I can create this virtual method and have every class derived from BaseForm return the concrete representation of the AbstractManager?</p>
  
  <p>If I get rid of the generic on the AbstractManager class then I compile OK (with a few code changes), but then the GetAll method can't return a <code>List&lt;T&gt;</code>. It would have to return a <code>List&lt;AbstractData&gt;</code> instead, which causes issues in converting from <code>List&lt;Person&gt;</code> to <code>List&lt;AbstractData&gt;</code>.</p>
  
  <p>Any help would be appreciated.</p>