title: How do I assign a child class to a generic field in a non-generic class
body: <p>In C#, I am trying to store a private generic variable in a non-generic class that is passed in through a generic method.
  The generic method is supposed to take child classes that are upcast to the base class type.</p>
  
  <p>Here is an example of the issue:</p>
  
  <pre><code>class BaseModel { }
  class DerivedModel : BaseModel { }
  
  class Data&lt;T&gt; where T : BaseModel { }
  
  // Class is NOT generic
  class DataConsumer
  {
      // How do I set this to generic?
      private Data&lt;BaseModel&gt; data;
  
      public void Set&lt;T&gt;(Data&lt;T&gt; data) where T : BaseModel
      {
          // Compile time error: 
          // Cannot convert source type 'Generic.Data&lt;T&gt; 
          // to target type 'Generic.Data&lt;Generic.BaseModel&gt;'
          this.data = data;
      }
  }
  </code></pre>