System.ComponentModel.ReflectPropertyDescriptor.RemoveValueChanged C# (CSharp) 메소드

RemoveValueChanged() 공개 메소드

Allows interested objects to be notified when this property changes.
public RemoveValueChanged ( object component, EventHandler handler ) : void
component object
handler EventHandler
리턴 void
        public override void RemoveValueChanged(object component, EventHandler handler)
        {
            if (component == null) throw new ArgumentNullException(nameof(component));
            if (handler == null) throw new ArgumentNullException(nameof(handler));

            // If there's an event called <propertyname>Changed, we hooked the caller's
            // handler directly up to that on the component, so remove it now.
            EventDescriptor changedEvent = ChangedEventValue;
            if (changedEvent != null && changedEvent.EventType.GetTypeInfo().IsInstanceOfType(handler))
            {
                changedEvent.RemoveEventHandler(component, handler);
            }

            // Otherwise the base class added the handler to its ValueChanged
            // event for this component, so let the base class remove it now.
            else
            {
                base.RemoveValueChanged(component, handler);

                // Special case: If that was the LAST handler removed for this component, and the component implements
                // INotifyPropertyChanged, the property descriptor must STOP listening to the generic PropertyChanged event
                if (GetValueChangedHandler(component) == null)
                {
                    EventDescriptor iPropChangedEvent = IPropChangedEventValue;
                    if (iPropChangedEvent != null)
                    {
                        iPropChangedEvent.RemoveEventHandler(component, new PropertyChangedEventHandler(OnINotifyPropertyChanged));
                    }
                }
            }
        }