title: How can I store generic classes of different types (all with a generic base class) in the same collection?
body: <p>I have a similar problem to the one in <a href="https://stackoverflow.com/questions/7066506/how-do-i-create-a-list-of-objects-that-inherit-from-the-same-generic-class-with">this post</a>.</p>
  
  <p>I have also seen the thousands of posts online that say that you can put any generic class that extends a particular base class into a collection of the type of the base class. I understand this perfectly well.</p>
  
  <p>My problem differs from the linked post above and the others in one basic way - my generic classes have a base class that is also generic. Worse still, this is part of a very large MVVM application framework (built in-house) and the generic base class also has a base class and so on... each base class adds certain properties and functionality and it looks a bit like this:</p>
  
  <blockquote>
    <p>DataListEntry&lt;T&gt; &lt;-- BaseSynchronisableDataType&lt;T&gt; &lt;--
    BaseAuditDataType &lt;-- BaseDataType &lt;-- BaseAnimatableDataType</p>
  </blockquote>
  
  <p>The application collection classes use similar inheritance:</p>
  
  <blockquote>
    <p>DataList&lt;T&gt; &lt;-- BaseSynchronisableCollection&lt;T&gt; &lt;--
    BaseAnimatableCollection&lt;T&gt; &lt;-- BaseCollection&lt;T&gt; &lt;--
    SortableObservableCollection&lt;T&gt;</p>
  </blockquote>
  
  <p>Even worse still, each generic declaration has constraints so that for instance, the definition of BaseSynchronisableDataType&lt;T&gt; looks like this:</p>
  
  <pre><code>public abstract class BaseSynchronisableDataType&lt;T&gt; : BaseAuditDataType, 
      ISynchronisable&lt;T&gt;, ICloneable&lt;T&gt;, IEquatable&lt;T&gt; where T : class, ICloneable&lt;T&gt;,
      IEquatable&lt;T&gt;, new()
  </code></pre>
  
  <p>So each generic collection type is tied through these constraints to a generic base class. Hopefully by now, you can see the scale of my problem.</p>
  
  <p>I have tried using interfaces (not shown above) to remove the link from the collections to their respective base classes, but this is also failing because of some of the generic constraints on related classes. For example, I couldn't create a collection of the type of an interface because there are neccessary generic 'class' constraints on some base classes and so I get errors saying that the type of the collection 'must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method'.</p>
  
  <p>One last point to note describes exactly what I am trying to do:</p>
  
  <p>I need to populate a collection with different classes that all extend the DataList&lt;T&gt; base class. These classes are different only in name and have exactly the same properties in them. They are declared as follows:</p>
  
  <pre><code>public class Writer : DataListEntry&lt;Writer&gt;    
  public class Artist : DataListEntry&lt;Artist&gt;etc.
  </code></pre>
  
  <p>If you have any ideas, then please let me know... I've suffered for 2 days on this problem already and my boss is none too pleased! Many thanks in advance, Sheridan.</p>