I've a some type (object of Type). Need to check that this type has interface IList.
How I can do this?
views:
395answers:
3
+4
A:
You can use the Type.GetInterface method.
if (object.GetType().GetInterface("IList") != null)
{
// object implements IList
}
CMS
2009-08-04 07:06:48
+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
2009-08-04 07:08:46
+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
2009-08-04 07:10:23
+1 This answered my question!!!
dboarman
2010-02-03 23:28:59