Updated question given Andrew Hare's correct answer:
Given the following C# classes:
public class Bar : Foo, IDisposable
{
// implementation of Bar and IDisposable
}
public class Foo : IEnumerable<int>
{
// implementation of Foo and all its inherited interfaces
}
I want a method like the following that doesn't fail on the assertions (Note: you cannot change the assertions):
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));
}
Can someone help by fixing this method so the assertions don't fail?
Calling typeof(Bar).GetInterfaces()
doesn't work because it returns the entire interface hierarchy (i.e. interfaces
variable contains IEnumerable<int>
, IEnumerable
, and IDisposable
), not just the top level.