private static object GetDebugInvokee(Type componentClass, object component) {
// We delve into the component's designer only if it is a component and if
// the component we've been handed is not an instance of this property type.
//
if (!componentClass.IsInstanceOfType(component) && component is IComponent) {
ISite site = ((IComponent)component).Site;
if (site != null && site.DesignMode) {
IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost));
if (host != null) {
object designer = host.GetDesigner((IComponent)component);
// We only use the designer if it has a compatible class. If we
// got here, we're probably hosed because the user just passed in
// an object that this PropertyDescriptor can't munch on, but it's
// clearer to use that object instance instead of it's designer.
//
if (designer != null && componentClass.IsInstanceOfType(designer)) {
component = designer;
}
}
}
}
Debug.Assert(component != null, "Attempt to invoke on null component");
return component;
}