When calling typeof(Bar).GetInterfaces() on the following scenario the method returns IFoo and IBar.
interface IFoo {}
interface IBar : IFoo {}
class Bar : IBar {}
Is there a way that I can find only the immediate interface (IBar) on Bar?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there’s no such thing as the “immediate” interface in the compiled code. Your class is effectively compiled as:
and you can’t distinguish between the two. The only thing you could do is to check all of them and see whether two or more of the interfaces inherit from each other or not (and even in that case, you can’t really check whether the author of the class has explicitly mentioned the base interface in code or not):