public override void SetValue(object component, object value)
{
Debug.WriteLine($"[{Name}]: SetValue({component?.GetType().Name ?? "(null)"}, {value?.GetType().Name ?? "(null)"})");
if (component != null)
{
ISite site = GetSite(component);
object oldValue = null;
object invokee = GetInvocationTarget(_componentClass, component);
if (!IsReadOnly)
{
IComponentChangeService changeService = null;
// Announce that we are about to change this component
//
if (site != null)
{
changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || changeService != null, "IComponentChangeService not found");
}
// Make sure that it is ok to send the onchange events
//
if (changeService != null)
{
oldValue = SecurityUtils.MethodInfoInvoke(GetMethodValue, invokee, (object[])null);
try
{
changeService.OnComponentChanging(component, this);
}
catch (CheckoutException coEx)
{
if (coEx == CheckoutException.Canceled)
{
return;
}
throw coEx;
}
}
try
{
try
{
SetMethodValue.Invoke(invokee, new object[] { value });
OnValueChanged(invokee, EventArgs.Empty);
}
catch (Exception t)
{
// Give ourselves a chance to unwind properly before rethrowing the exception.
//
value = oldValue;
// If there was a problem setting the controls property then we get:
// ArgumentException (from properties set method)
// ==> Becomes inner exception of TargetInvocationException
// ==> caught here
if (t is TargetInvocationException && t.InnerException != null)
{
// Propagate the original exception up
throw t.InnerException;
}
else
{
throw t;
}
}
}
finally
{
// Now notify the change service that the change was successful.
//
if (changeService != null)
{
changeService.OnComponentChanged(component, this, oldValue, value);
}
}
}
}
}