Let\'s say I have a type, MyType. I want to do the following:
As a helper method extension
public static bool Implements(this Type type, I @interface) where I : class
{
if(((@interface as Type)==null) || !(@interface as Type).IsInterface)
throw new ArgumentException("Only interfaces can be 'implemented'.");
return (@interface as Type).IsAssignableFrom(type);
}
example usage:
var testObject = new Dictionary();
result = testObject.GetType().Implements(typeof(IDictionary)); // true!