System.ComponentModel.ReflectPropertyDescriptor.AddValueChanged C# (CSharp) Method

AddValueChanged() public method

Allows interested objects to be notified when this property changes.
public AddValueChanged ( object component, EventHandler handler ) : void
component object
handler EventHandler
return void
        public override void AddValueChanged(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, hook the caller's handler directly up to that on the component
            EventDescriptor changedEvent = ChangedEventValue;
            if (changedEvent != null && changedEvent.EventType.GetTypeInfo().IsInstanceOfType(handler))
            {
                changedEvent.AddEventHandler(component, handler);
            }

            // Otherwise let the base class add the handler to its ValueChanged event for this component
            else
            {
                // Special case: If this will be the FIRST handler added for this component, and the component implements
                // INotifyPropertyChanged, the property descriptor must START listening to the generic PropertyChanged event
                if (GetValueChangedHandler(component) == null)
                {
                    EventDescriptor iPropChangedEvent = IPropChangedEventValue;
                    if (iPropChangedEvent != null)
                    {
                        iPropChangedEvent.AddEventHandler(component, new PropertyChangedEventHandler(OnINotifyPropertyChanged));
                    }
                }

                base.AddValueChanged(component, handler);
            }
        }