title: How do I enumerate a list of interfaces that are directly defined on an inheriting class?
body: <p><strong>Updated question given Andrew Hare's correct answer:</strong></p>
  
  <p>Given the following C# classes:</p>
  
  <pre><code>public class Bar : Foo, IDisposable
  {
      // implementation of Bar and IDisposable
  }
  
  public class Foo : IEnumerable&lt;int&gt;
  {
      // implementation of Foo and all its inherited interfaces
  }
  </code></pre>
  
  <p>I want a method like the following that doesn't fail on the assertions (<strong>Note: you cannot change the assertions</strong>):</p>
  
  <pre><code>public void SomeMethod()
  {
     // This doesn't work
     Type[] interfaces = typeof(Bar).GetInterfaces();
  
     Debug.Assert(interfaces != null);
     Debug.Assert(interfaces.Length == 1);
     Debug.Assert(interfaces[0] == typeof(IDisposable));
  }
  </code></pre>
  
  <p>Can someone help by fixing this method so the assertions don't fail?</p>
  
  <p>Calling <code>typeof(Bar).GetInterfaces()</code> doesn't work because it returns the entire interface hierarchy (i.e. <code>interfaces</code> variable contains <code>IEnumerable&lt;int&gt;</code>, <code>IEnumerable</code>, and <code>IDisposable</code>), not just the top level.</p>