title: Where() at abstract level to return new self
body: <p>I have this code and I want to keep it elegant.<br>
  I got stuck at this inheriting issue and I would have to mess up the code if I do.<br>
  Help me keep it elegant.  I don't mind making changes anywhere up and down the hierarchy; feel free to change the core.</p>
  
  <p>I have these abstract classes (I omitted unrelated implementation to keep the question content short).</p>
  
  <pre><code>public abstract class Entity : IComparable 
  { 
      protected int _ID;
      public abstract int ID { get; } 
  }    
  public abstract class SortedEntities&lt;T&gt; : IEnumerable&lt;T&gt; where T : Entity 
  { 
      Dictionary&lt;int,T&gt; _Entities;
  }
  </code></pre>
  
  <p>And, obviously, an example of inheritance is as follows:</p>
  
  <pre><code>public class Contact : Entity { }
  public class Contacts : SortedEntities&lt;Contact&gt; { }
  </code></pre>
  
  <p>And I also have more than just <code>Contact</code> and <code>Contacts</code> that inherit from <code>Entity</code> and <code>SortedEntities</code> that all act in the same manner.  </p>
  
  <p>At some point in my app, I want to select entities based on and ID list.<br>
  A sample code of what I want is:  </p>
  
  <pre><code>Contacts LoadedContacts = new Contacts();  // load and fill somewhere else
  // !!!NOT IMPLEMENTED YET!!!
  Contacts SelectedContacts = LoadedContacts.GetFromIDList("1,4,7");
  </code></pre>
  
  <p>Where it returns a new <code>Contacts</code> object filled with those <code>Contact</code> objects of the ID's provided.<br>
  So, to allow that code for all classes inheriting from <code>SortedEntities</code>, I thought of adding this imaginative code to the abstract:</p>
  
  <pre><code>public abstract class SortedEntities&lt;T&gt; : IEnumerable&lt;T&gt; where T : Entity 
  {
      // !!!NOT REAL CODE YET!!!
      public abstract this&lt;T&gt; GetFromIDList(string IDCSV)
      {
          List&lt;string&gt; idlist = IDCSV.Split(',').ToList&lt;string&gt;();
          return this.Where(entity =&gt; idlist.Contains(entity.ID.ToString()));
      }
  }
  </code></pre>
  
  <p>But obviously the <code>this&lt;T&gt;</code> is not allowed.<br>
  What I'm trying to tell the compiler is to make the return type of this method that of the inheriting class down the hierarchy.<br>
  That way, if someone calls <code>LoadedContacts.GetFromIDList("1,4,7")</code> it will return <code>Contacts</code> without having to cast it from <code>SortedEntities&lt;T&gt;</code> if I make it the return type, which would also require me to override the method in each inheriting class to hide the abstract method.  </p>
  
  <p>Am I forgetting something I already know?<br>
  Or is this completely not possible and I have to override and hide the method down the hierarchy for all inheriting classes?</p>