title: How to hold base and derived class with generics on list in c#?
body: <p>We have the base CharFieldSchema class which is derived from BaseSchema and CharFieldValidator which is derived from BaseValidator and passing BaseValidator as generics to BaseSchema for Validator property.BaseValidator also has CharFieldValidator as a derived class. But not able to hold derived classes on the list.</p>
  <p>For example:</p>
  <pre><code>var x= new List&lt;BaseSchema&lt;BaseValidator&gt;&gt;();
             x.Add(new BaseSchema&lt;BaseValidator&gt;());
             x.Add(new CharFieldSchema&lt;CharFieldValidator&gt;());
  </code></pre>
  <p>got error <code>Cannot resolve method 'Add(CharFieldSchema&lt;dculus.forms.core.Dto.FormValidator.CharFieldValidator&gt;)', candidates are: void Add(BaseSchema&lt;dculus.forms.core.Dto.FormValidator.BaseValidator&gt;) (in class List&lt;BaseSchema&lt;BaseValidator&gt;&gt;)</code></p>
  <p>So, is it need to make any changes on the List generic type?</p>
  <p><code>BaseSchema.cs</code></p>
  <pre><code>public class BaseSchema&lt;T&gt;
  {
      public string Id { set; get; }
      public virtual string Type { get; }
      public T Validator { set; get; }
  }
  </code></pre>
  <p><code>CharFieldSchema.cs</code></p>
  <pre><code>public class CharFieldSchema&lt;T&gt; : BaseSchema&lt;T&gt; 
  {
      public override string Type { get; } = &quot;charField&quot;;
      public string DefaultValue { set; get; }   
  }
  </code></pre>
  <p><code>BaseValidator.cs</code></p>
  <pre><code>public class BaseValidator
  {
      public virtual string Type { get; }
      public bool Require { get; }
  }
  </code></pre>
  <p><code>CharFieldValidator.cs</code></p>
  <pre><code>public class CharFieldValidator : BaseValidator
  {
      public override string Type { get; } = &quot;charFieldV&quot;;
      public int MinLength { set; get; }
      public int MaxLength { set; get; }
  }
  </code></pre>