public override bool Equals(Object otherClosure) { if (otherClosure is ReferenceEventClosure) { ReferenceEventClosure typedClosure = (ReferenceEventClosure)otherClosure; return(typedClosure.reference == reference && typedClosure.propertyDescriptor == propertyDescriptor); } return(false); }
public override bool Equals(object otherClosure) { if (!(otherClosure is ReferenceEventClosure)) { return(false); } ReferenceEventClosure closure = (ReferenceEventClosure)otherClosure; return((closure.reference == this.reference) && closure.propertyDescriptor.Equals(this.propertyDescriptor)); }
/// <summary> /// This will set value to be the new value of this property on the /// component by invoking the setXXX method on the component. If the /// value specified is invalid, the component should throw an exception /// which will be passed up. The component designer should design the /// property so that getXXX following a setXXX should return the value /// passed in if no exception was thrown in the setXXX call. /// </summary> public override void SetValue(object component, object value) { // Argument, state checking. Is it ok to set this event? if (IsReadOnly) { Exception ex = new InvalidOperationException(string.Format(SR.EventBindingServiceEventReadOnly, Name)); ex.HelpLink = SR.EventBindingServiceEventReadOnly; throw ex; } if (value != null && !(value is string)) { Exception ex = new ArgumentException(string.Format(SR.EventBindingServiceBadArgType, Name, typeof(string).Name)); ex.HelpLink = SR.EventBindingServiceBadArgType; throw ex; } string name = (string)value; if (name != null && name.Length == 0) { name = null; } // Obtain the site for the component. Note that this can be a site // to a parent component if we can get to the reference service. ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site is null && (_eventSvc._provider.GetService(typeof(IReferenceService)) is IReferenceService rs)) { IComponent baseComponent = rs.GetComponent(component); if (baseComponent != null) { site = baseComponent.Site; } } if (site is null) { Exception ex = new InvalidOperationException(SR.EventBindingServiceNoSite); ex.HelpLink = SR.EventBindingServiceNoSite; throw ex; } // The dictionary service is where we store the actual event method name. if (!(site.GetService(typeof(IDictionaryService)) is IDictionaryService ds)) { Exception ex = new InvalidOperationException(string.Format(SR.EventBindingServiceMissingService, typeof(IDictionaryService).Name)); ex.HelpLink = SR.EventBindingServiceMissingService; throw ex; } // Get the old method name, ensure that they are different, and then continue. ReferenceEventClosure key = new ReferenceEventClosure(component, this); string oldName = (string)ds.GetValue(key); if (object.ReferenceEquals(oldName, name)) { return; } if (oldName != null && name != null && oldName.Equals(name)) { return; } // Before we continue our work, ensure that the name is actually valid. if (name != null) { _eventSvc.ValidateMethodName(name); } // If there is a designer host, create a transaction so there is a // nice name for this change. We don't want a name like // "Change property 'Click', because to users, this isn't a property. DesignerTransaction trans = null; if (site.GetService(typeof(IDesignerHost)) is IDesignerHost host) { trans = host.CreateTransaction(string.Format(SR.EventBindingServiceSetValue, site.Name, name)); } try { // Ok, the names are different. Fire a changing event to make // sure it's OK to perform the change. IComponentChangeService change = site.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (change != null) { try { change.OnComponentChanging(component, this); change.OnComponentChanging(component, Event); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } } // Less chance of success of adding a new method name, so // don't release the old name until we verify that adding // the new one actually succeeded. if (name != null) { _eventSvc.UseMethod((IComponent)component, Event, name); } if (oldName != null) { _eventSvc.FreeMethod((IComponent)component, Event, oldName); } ds.SetValue(key, name); if (change != null) { change.OnComponentChanged(component, Event, null, null); change.OnComponentChanged(component, this, oldName, name); } OnValueChanged(component, EventArgs.Empty); if (trans != null) { trans.Commit(); } } finally { if (trans != null) { ((IDisposable)trans).Dispose(); } } }
/// This will set value to be the new value of this property on the /// component by invoking the setXXX method on the component. If the /// value specified is invalid, the component should throw an exception /// which will be passed up. The component designer should design the /// property so that getXXX following a setXXX should return the value /// passed in if no exception was thrown in the setXXX call. public override void SetValue(object component, object value) { // Argument, state checking. Is it ok to set this event? // if (IsReadOnly) { Exception ex = new InvalidOperationException("Tried to set a read only event."); throw ex; } if (value != null && !(value is string)) { Exception ex = new ArgumentException("Cannot set to value " + value.ToString() + "."); throw ex; } string name = (string)value; if (name != null && name.Length == 0) { name = null; } // Obtain the site for the component. Note that this can be a site // to a parent component if we can get to the reference service. // ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site == null) { IReferenceService rs = _eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (rs != null) { IComponent baseComponent = rs.GetComponent(component); if (baseComponent != null) { site = baseComponent.Site; } } } if (site == null) { Exception ex = new InvalidOperationException("There is no site for component " + component.ToString() + "."); throw ex; } // The dictionary service is where we store the actual event method name. // IDictionaryService ds = (IDictionaryService)site.GetService(typeof(IDictionaryService)); if (ds == null) { Exception ex = new InvalidOperationException("Cannot find IDictionaryService"); throw ex; } // Get the old method name, ensure that they are different, and then continue. // ReferenceEventClosure key = new ReferenceEventClosure(component, this); string oldName = (string)ds.GetValue(key); if (object.ReferenceEquals(oldName, name)) { return; } if (oldName != null && name != null && oldName.Equals(name)) { return; } // Before we continue our work, ensure that the name is // actually valid. // if (name != null) { _eventSvc.ValidateMethodName(name); } // Ok, the names are different. Fire a changing event to make // sure it's OK to perform the change. // IComponentChangeService change = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (change != null) { try { change.OnComponentChanging(component, this); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } } // Less chance of success of adding a new method name, so // don't release the old name until we verify that adding // the new one actually succeeded. // if (name != null) { _eventSvc.UseMethod(component, _eventDesc, name); } if (oldName != null) { _eventSvc.FreeMethod(component, _eventDesc, oldName); } ds.SetValue(key, name); if (change != null) { change.OnComponentChanged(component, this, oldName, name); } OnValueChanged(component, EventArgs.Empty); }
/// This will set value to be the new value of this property on the /// component by invoking the setXXX method on the component. If the /// value specified is invalid, the component should throw an exception /// which will be passed up. The component designer should design the /// property so that getXXX following a setXXX should return the value /// passed in if no exception was thrown in the setXXX call. public override void SetValue(object component, object value) { // Argument, state checking. Is it ok to set this event? // if (IsReadOnly) { Exception ex = new InvalidOperationException("Tried to set a read only event."); throw ex; } if (value != null && !(value is string)) { Exception ex = new ArgumentException("Cannot set to value " + value.ToString() + "."); throw ex; } string name = (string)value; if (name != null && name.Length == 0) { name = null; } // Obtain the site for the component. Note that this can be a site // to a parent component if we can get to the reference service. // ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site == null) { IReferenceService rs = _eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (rs != null) { IComponent baseComponent = rs.GetComponent(component); if (baseComponent != null) { site = baseComponent.Site; } } } if (site == null) { Exception ex = new InvalidOperationException("There is no site for component " + component.ToString() + "."); throw ex; } // The dictionary service is where we store the actual event method name. // IDictionaryService ds = (IDictionaryService)site.GetService(typeof(IDictionaryService)); if (ds == null) { Exception ex = new InvalidOperationException("Cannot find IDictionaryService"); throw ex; } // Get the old method name, ensure that they are different, and then continue. // ReferenceEventClosure key = new ReferenceEventClosure(component, this); string oldName = (string)ds.GetValue(key); if (object.ReferenceEquals(oldName, name)) { return; } if (oldName != null && name != null && oldName.Equals(name)) { return; } // Before we continue our work, ensure that the name is // actually valid. // if (name != null) { _eventSvc.ValidateMethodName(name); } // Ok, the names are different. Fire a changing event to make // sure it's OK to perform the change. // IComponentChangeService change = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (change != null) { try { change.OnComponentChanging(component, this); } catch(CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } } // Less chance of success of adding a new method name, so // don't release the old name until we verify that adding // the new one actually succeeded. // if (name != null) { _eventSvc.UseMethod(component, _eventDesc, name); } if (oldName != null) { _eventSvc.FreeMethod(component, _eventDesc, oldName); } ds.SetValue(key, name); if (change != null) { change.OnComponentChanged(component, this, oldName, name); } OnValueChanged(component, EventArgs.Empty); }
public override void SetValue(object component, object value) { if (this.IsReadOnly) { Exception exception = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceEventReadOnly", new object[] { this.Name })) { HelpLink = "EventBindingServiceEventReadOnly" }; throw exception; } if ((value != null) && !(value is string)) { Exception exception2 = new ArgumentException(System.Design.SR.GetString("EventBindingServiceBadArgType", new object[] { this.Name, typeof(string).Name })) { HelpLink = "EventBindingServiceBadArgType" }; throw exception2; } string objB = (string) value; if ((objB != null) && (objB.Length == 0)) { objB = null; } ISite site = null; if (component is IComponent) { site = ((IComponent) component).Site; } if (site == null) { IReferenceService service = this._eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (service != null) { IComponent component2 = service.GetComponent(component); if (component2 != null) { site = component2.Site; } } } if (site == null) { Exception exception3 = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceNoSite")) { HelpLink = "EventBindingServiceNoSite" }; throw exception3; } IDictionaryService service2 = site.GetService(typeof(IDictionaryService)) as IDictionaryService; if (service2 == null) { Exception exception4 = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceMissingService", new object[] { typeof(IDictionaryService).Name })) { HelpLink = "EventBindingServiceMissingService" }; throw exception4; } ReferenceEventClosure key = new ReferenceEventClosure(component, this); string objA = (string) service2.GetValue(key); if (!object.ReferenceEquals(objA, objB) && (((objA == null) || (objB == null)) || !objA.Equals(objB))) { if (objB != null) { this._eventSvc.ValidateMethodName(objB); } IDesignerHost host = site.GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if (host != null) { transaction = host.CreateTransaction(System.Design.SR.GetString("EventBindingServiceSetValue", new object[] { site.Name, objB })); } try { IComponentChangeService service3 = site.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (service3 != null) { try { service3.OnComponentChanging(component, this); service3.OnComponentChanging(component, this.Event); } catch (CheckoutException exception5) { if (exception5 != CheckoutException.Canceled) { throw; } return; } } if (objB != null) { this._eventSvc.UseMethod((IComponent) component, this._eventDesc, objB); } if (objA != null) { this._eventSvc.FreeMethod((IComponent) component, this._eventDesc, objA); } service2.SetValue(key, objB); if (service3 != null) { service3.OnComponentChanged(component, this.Event, null, null); service3.OnComponentChanged(component, this, objA, objB); } this.OnValueChanged(component, EventArgs.Empty); if (transaction != null) { transaction.Commit(); } } finally { if (transaction != null) { ((IDisposable) transaction).Dispose(); } } } }
public override void SetValue(object component, object value) { Exception ex; if (this.IsReadOnly) { ex = new InvalidOperationException("Tried to set a read only event."); throw ex; } if (!((value == null) || (value is string))) { ex = new ArgumentException("Cannot set to value " + value.ToString() + "."); throw ex; } string name = (string)value; if ((name != null) && (name.Length == 0)) { name = null; } ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site == null) { IReferenceService rs = this._eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (rs != null) { IComponent baseComponent = rs.GetComponent(component); if (baseComponent != null) { site = baseComponent.Site; } } } if (site == null) { ex = new InvalidOperationException("There is no site for component " + component.ToString() + "."); throw ex; } IDictionaryService ds = (IDictionaryService)site.GetService(typeof(IDictionaryService)); if (ds == null) { ex = new InvalidOperationException("Cannot find IDictionaryService"); throw ex; } ReferenceEventClosure key = new ReferenceEventClosure(component, this); string oldName = (string)ds.GetValue(key); if (!object.ReferenceEquals(oldName, name) && (((oldName == null) || (name == null)) || !oldName.Equals(name))) { if (name != null) { this._eventSvc.ValidateMethodName(name); } IComponentChangeService change = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (change != null) { try { change.OnComponentChanging(component, this); } catch (CheckoutException coEx) { if (coEx != CheckoutException.Canceled) { throw; } return; } } if (name != null) { this._eventSvc.UseMethod(component, this._eventDesc, name); } if (oldName != null) { this._eventSvc.FreeMethod(component, this._eventDesc, oldName); } ds.SetValue(key, name); if (change != null) { change.OnComponentChanged(component, this, oldName, name); } this.OnValueChanged(component, EventArgs.Empty); } }
public override void SetValue(object component, object value) { if (this.IsReadOnly) { Exception exception = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceEventReadOnly", new object[] { this.Name })) { HelpLink = "EventBindingServiceEventReadOnly" }; throw exception; } if ((value != null) && !(value is string)) { Exception exception2 = new ArgumentException(System.Design.SR.GetString("EventBindingServiceBadArgType", new object[] { this.Name, typeof(string).Name })) { HelpLink = "EventBindingServiceBadArgType" }; throw exception2; } string objB = (string)value; if ((objB != null) && (objB.Length == 0)) { objB = null; } ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site == null) { IReferenceService service = this._eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (service != null) { IComponent component2 = service.GetComponent(component); if (component2 != null) { site = component2.Site; } } } if (site == null) { Exception exception3 = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceNoSite")) { HelpLink = "EventBindingServiceNoSite" }; throw exception3; } IDictionaryService service2 = site.GetService(typeof(IDictionaryService)) as IDictionaryService; if (service2 == null) { Exception exception4 = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceMissingService", new object[] { typeof(IDictionaryService).Name })) { HelpLink = "EventBindingServiceMissingService" }; throw exception4; } ReferenceEventClosure key = new ReferenceEventClosure(component, this); string objA = (string)service2.GetValue(key); if (!object.ReferenceEquals(objA, objB) && (((objA == null) || (objB == null)) || !objA.Equals(objB))) { if (objB != null) { this._eventSvc.ValidateMethodName(objB); } IDesignerHost host = site.GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if (host != null) { transaction = host.CreateTransaction(System.Design.SR.GetString("EventBindingServiceSetValue", new object[] { site.Name, objB })); } try { IComponentChangeService service3 = site.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (service3 != null) { try { service3.OnComponentChanging(component, this); service3.OnComponentChanging(component, this.Event); } catch (CheckoutException exception5) { if (exception5 != CheckoutException.Canceled) { throw; } return; } } if (objB != null) { this._eventSvc.UseMethod((IComponent)component, this._eventDesc, objB); } if (objA != null) { this._eventSvc.FreeMethod((IComponent)component, this._eventDesc, objA); } service2.SetValue(key, objB); if (service3 != null) { service3.OnComponentChanged(component, this.Event, null, null); service3.OnComponentChanged(component, this, objA, objB); } this.OnValueChanged(component, EventArgs.Empty); if (transaction != null) { transaction.Commit(); } } finally { if (transaction != null) { ((IDisposable)transaction).Dispose(); } } } }
public override void SetValue(object component, object value) { Exception ex; if (this.IsReadOnly) { ex = new InvalidOperationException("Tried to set a read only event."); throw ex; } if (!((value == null) || (value is string))) { ex = new ArgumentException("Cannot set to value " + value.ToString() + "."); throw ex; } string name = (string) value; if ((name != null) && (name.Length == 0)) { name = null; } ISite site = null; if (component is IComponent) { site = ((IComponent) component).Site; } if (site == null) { IReferenceService rs = this._eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (rs != null) { IComponent baseComponent = rs.GetComponent(component); if (baseComponent != null) { site = baseComponent.Site; } } } if (site == null) { ex = new InvalidOperationException("There is no site for component " + component.ToString() + "."); throw ex; } IDictionaryService ds = (IDictionaryService) site.GetService(typeof(IDictionaryService)); if (ds == null) { ex = new InvalidOperationException("Cannot find IDictionaryService"); throw ex; } ReferenceEventClosure key = new ReferenceEventClosure(component, this); string oldName = (string) ds.GetValue(key); if (!object.ReferenceEquals(oldName, name) && (((oldName == null) || (name == null)) || !oldName.Equals(name))) { if (name != null) { this._eventSvc.ValidateMethodName(name); } IComponentChangeService change = (IComponentChangeService) site.GetService(typeof(IComponentChangeService)); if (change != null) { try { change.OnComponentChanging(component, this); } catch (CheckoutException coEx) { if (coEx != CheckoutException.Canceled) { throw; } return; } } if (name != null) { this._eventSvc.UseMethod(component, this._eventDesc, name); } if (oldName != null) { this._eventSvc.FreeMethod(component, this._eventDesc, oldName); } ds.SetValue(key, name); if (change != null) { change.OnComponentChanged(component, this, oldName, name); } this.OnValueChanged(component, EventArgs.Empty); } }