I've a some type (object of Type
). Need to check that this type has interface IList.
How I can do this?
Assuming you have an object type
with the type System.Type
(what I gathered from the OP),
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
.
So from your example:
Type customListType = new YourCustomListType().GetType();
if (typeof(IList).IsAssignableFrom(customListType))
{
//Will be true if "YourCustomListType : IList"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With