I have some type ( Type object). You must verify that this type has an IList interface.How can i do this?
Type
Assuming you have a type object with type System.Type (which I compiled from OP),
type
System.Type
Type type = ...; typeof(IList).IsAssignableFrom(type)
You can use the Type.GetInterface method.
if (object.GetType().GetInterface("IList") != null) { // object implements IList }
I think the easiest way is to use IsAssignableFrom .
IsAssignableFrom
So from your example:
Type customListType = new YourCustomListType().GetType(); if (typeof(IList).IsAssignableFrom(customListType)) { //Will be true if "YourCustomListType : IList" }
You can use is to check:
is
MyType obj = new MyType(); if (obj is IList) { // obj implements IList }