title: Generic class with where constraint on base class, but only allowing derived classes
body: <p>I have a class <code>MediaCollection&lt;T&gt;</code> that represents a playlists of songs, videos or pictures. I also have three classes: <code>Song</code>, <code>Video</code> and <code>Picture</code> that all inherits from a <code>AMediaElement</code> abstract class. My <code>MediaCollection&lt;T&gt;</code> class has the following constraints:</p>
  
  <pre><code>class MediaCollection&lt;T&gt;
      where T : AMediaElement, new()
  {
  }
  </code></pre>
  
  <p>This allows me to have collections of songs, pictures, videos but also of just any <code>AMediaElement</code>!</p>
  
  <p>How can I prevent the creation of objects of type <code>MediaCollection&lt;AMediaElement&gt;</code>? I could make the <code>MediaCollection</code> abstract and then make three other classes <code>SongCollection</code>, <code>PictureCollection</code> and <code>VideoCollection</code>, but I would prefer a solution using the <code>where</code> clause.</p>