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

ExtenderResetValue() private method

private ExtenderResetValue ( IExtenderProvider provider, object component, PropertyDescriptor notifyDesc ) : void
provider IExtenderProvider
component object
notifyDesc PropertyDescriptor
return void
        internal void ExtenderResetValue(IExtenderProvider provider, object component, PropertyDescriptor notifyDesc)
        {
            if (DefaultValue != s_noValue)
            {
                ExtenderSetValue(provider, component, DefaultValue, notifyDesc);
            }
            else if (AmbientValue != s_noValue)
            {
                ExtenderSetValue(provider, component, AmbientValue, notifyDesc);
            }
            else if (ResetMethodValue != null)
            {
                ISite site = GetSite(component);
                IComponentChangeService changeService = null;
                object oldValue = null;
                object newValue;

                // 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 = ExtenderGetValue(provider, component);
                    try
                    {
                        changeService.OnComponentChanging(component, notifyDesc);
                    }
                    catch (CheckoutException coEx)
                    {
                        if (coEx == CheckoutException.Canceled)
                        {
                            return;
                        }
                        throw coEx;
                    }
                }

                provider = (IExtenderProvider)GetInvocationTarget(_componentClass, provider);
                if (ResetMethodValue != null)
                {
                    ResetMethodValue.Invoke(provider, new object[] { component });

                    // Now notify the change service that the change was successful.
                    //
                    if (changeService != null)
                    {
                        newValue = ExtenderGetValue(provider, component);
                        changeService.OnComponentChanged(component, notifyDesc, oldValue, newValue);
                    }
                }
            }
        }

Usage Example

 /// <summary>
 ///     Resets the value of this property on comp to the default value.
 /// </summary>
 public override void ResetValue(object comp)
 {
     _extenderInfo.ExtenderResetValue(_provider, comp, this);
 }