title: List filtering using multiple classes/interfaces
body: <p>Basically I have a list of objects where each object might implement a different set of interfaces:</p>
  
  <pre><code>List&lt;BaseObject&gt; objects;
  
  class BaseObject
  {
    public void DoStuff();
  }
  
  interface IX
  {
    void DoX();
  }
  
  interface IY
  {
    void DoY();
  }
  
  interface IZ
  {
    void DoZ();
  }
  </code></pre>
  
  <p>And i would like to write something like this:</p>
  
  <pre><code>foreach(var obj in objects.OfType&lt;BaseObject and IX&gt;)
  {
    obj.DoStuff();
    obj.DoX();
  }
  </code></pre>
  
  <p>(E.g. i perform a specific algorithm for objects of type BaseObject and IX without having to do typecasts there)</p>
  
  <p>Is it possible to do in C#?
  What's the most elegant solution?</p>
  
  <p>I can do this:</p>
  
  <pre><code>foreach(var obj in objects.OfType&lt;IX&gt;)
  {
    var baseobj = (BaseObject)obj.DoStuff();
    obj.DoX();
  }
  </code></pre>
  
  <p>But i find it ugly.</p>
  
  <p>And I might need to apply specific operations to types that implement say interface IX and interface IZ.</p>
  
  <pre><code>foreach(var obj in objects.OfType&lt;BaseType and IX and IZ&gt;)
  {
    obj.DoStuff();
    obj.DoX();
    obj.DoZ();
  }
  </code></pre>