It's just a service locater type of pattern I am trying to implement, where I'd like to catch an attempt to register an implementation to an interface it doesn't belong to, as in:
public void Add(Type interfaceType, object implementingObject)
{
// ... check for nulls
// NO GOOD
if(!implementingObject.GetType().IsAssignableFrom(interfaceType)...
// NO GOOD
if(!implementingObject.GetType().IsInstanceOf(interfaceType)...
// FINALLY!
if(!implementingObject.GetType().BaseType.IsAssignableFrom(interfaceType)...
// ... ok, add it
}
Now I finaly figured out to use BaseType.IsInstanceOf by looking inside NUnit's isInstanceOf assertion, but it still seems unituitive.
Can someone explain why this makes sense? Is there some easier way to do this?