How to I find out if an class inherits from another type: class Dogs : List<Dog>

How to I find out if an class inherits from another type?

Example:
public class Dogs : List<Dog>
{
}

I want to check if Dogs inplements/inherits from IEnumerable.

Is there a way to do that through IClassDeclaration or IClass?

2 comments
Comment actions Permalink

You can use the TypeElementUtil.GetAllSuperTypes extension method on IClass (well, ITypeElement) to return a list of declared elements that represent the hierarchy. You can then examine each element, get its fully qualified name, etc, and check to see if it's what you're after.

0
Comment actions Permalink

Thank you. That worked great!

0

Please sign in to leave a comment.