tags:

views:

395

answers:

3

I've a some type (object of Type). Need to check that this type has interface IList.
How I can do this?

+4  A: 

You can use the Type.GetInterface method.

if (object.GetType().GetInterface("IList") != null)
{
    // object implements IList
}
CMS
+2  A: 

I think the easiest way is to use IsAssignableFrom.

So from your example:

Type customListType = new YourCustomListType().GetType();

if (typeof(IList).IsAssignableFrom(customListType))
{
    //Will be true if "YourCustomListType : IList"
}
Alconja
+5  A: 

Assuming you have an object type with the type System.Type (what I gathered from the OP),

Type type = ...;
typeof(IList).IsAssignableFrom(type)
280Z28
+1 This answered my question!!!
dboarman