title: Objects using different inherited interfaces in one List
body: <p><strong>The Goal</strong></p>
  <p>I want to have a number of Actors that act on a 3D scene using a variety of selectors that can be exchanged at runtime. Right now there are two types of Selectors, those that act on Positions and those that act on Objects. E.g. a DeleteActor will act on objects using a variety of Object selectors (only blue objects, only round ones, all connected objects etc).</p>
  <p><strong>The interfaces:</strong></p>
  <pre class="lang-cs prettyprint-override"><code>public interface IPosSelector {
      HashSet&lt;GridPos&gt; SelectedPositions { get; }
  }
  
  // this is really just a slight addition to IPosSelector, 
  // much of the functionality is the same, hence the inheritance
  public interface IObjectSelector : IPosSelector {
      HashSet&lt;GridObject&gt; SelectedObjects { get; }
  }
  
  public interface IActor {
      IPosSelector Selector { get; }
  }
  </code></pre>
  <p><strong>The classes using those interfaces:</strong></p>
  <pre class="lang-cs prettyprint-override"><code>
  // Actors use the selectors
  public class ObjectActor : IActor {
      IObjectSelector Selector { ... } // error because of wrong return type (wants IPosSelector)
  }
  public class PosActor : IActor {
      IPosSelector Selector { ... }
  }
  
  // keeps track of them and switches the Selectors on them at runtime
  public class Actors {
      List&lt;IActor&gt; actors;
      actors[0].Selector = ....
  }
  </code></pre>
  <p><strong>The problem</strong></p>
  <p>How can I organize the relationship between these components cleanly? I am getting a bit stuck with the design here and I feel like it should be simpler. As written, the code doesn't work because every <code>IActor</code> needs to implement <code>IPosSelector Selector</code>, not one of the inherited interfaces like <code>IObjectSelector</code>. So a few ideas came to mind but there are some issues with each:</p>
  <ol>
  <li>Make <code>IActor</code> generic... e.g. <code>IActor&lt;T&gt; where T : IPosSelector</code>
  <ul>
  <li>But how do I do put them in a list then? I would need a common interface which would need to have ISelector in there so the original issue remains.</li>
  </ul>
  </li>
  <li>Make all <code>IActor</code> implementations use the base <code>IPosSelector</code>, and then cast internally to <code>IObjectSelector</code> where appropriate.
  <ul>
  <li>But the structure should enforce which Actor works with which kind of Selector. Though I could do type checking in the property setter...</li>
  </ul>
  </li>
  </ol>