GetSite() protected static method

Gets a component site for the given component.

protected static GetSite ( object component ) : ISite
component object
return ISite
Ejemplo n.º 1
0
 public override void SetValue(object component, object value)
 {
     if (component != null)
     {
         ISite site = MemberDescriptor.GetSite(component);
         IComponentChangeService service = null;
         object oldValue         = null;
         object invocationTarget = this.GetInvocationTarget(this.componentClass, component);
         if (!this.IsReadOnly)
         {
             if (site != null)
             {
                 service = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
             }
             if (service != null)
             {
                 oldValue = SecurityUtils.MethodInfoInvoke(this.GetMethodValue, invocationTarget, null);
                 try
                 {
                     service.OnComponentChanging(component, this);
                 }
                 catch (CheckoutException exception)
                 {
                     if (exception != CheckoutException.Canceled)
                     {
                         throw exception;
                     }
                     return;
                 }
             }
             try
             {
                 SecurityUtils.MethodInfoInvoke(this.SetMethodValue, invocationTarget, new object[] { value });
                 this.OnValueChanged(invocationTarget, EventArgs.Empty);
             }
             catch (Exception exception2)
             {
                 value = oldValue;
                 if ((exception2 is TargetInvocationException) && (exception2.InnerException != null))
                 {
                     throw exception2.InnerException;
                 }
                 throw exception2;
             }
             finally
             {
                 if (service != null)
                 {
                     service.OnComponentChanged(component, this, oldValue, value);
                 }
             }
         }
     }
 }
 public override void AddEventHandler(object component, Delegate value)
 {
     this.FillMethods();
     if (component != null)
     {
         ISite site = MemberDescriptor.GetSite(component);
         IComponentChangeService service = null;
         if (site != null)
         {
             service = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
         }
         if (service != null)
         {
             try
             {
                 service.OnComponentChanging(component, this);
             }
             catch (CheckoutException exception)
             {
                 if (exception != CheckoutException.Canceled)
                 {
                     throw exception;
                 }
                 return;
             }
         }
         bool flag = false;
         if ((site != null) && site.DesignMode)
         {
             if (this.EventType != value.GetType())
             {
                 throw new ArgumentException(SR.GetString("ErrorInvalidEventHandler", new object[] { this.Name }));
             }
             IDictionaryService service2 = (IDictionaryService)site.GetService(typeof(IDictionaryService));
             if (service2 != null)
             {
                 Delegate a = (Delegate)service2.GetValue(this);
                 a = Delegate.Combine(a, value);
                 service2.SetValue(this, a);
                 flag = true;
             }
         }
         if (!flag)
         {
             SecurityUtils.MethodInfoInvoke(this.addMethod, component, new object[] { value });
         }
         if (service != null)
         {
             service.OnComponentChanged(component, this, null, value);
         }
     }
 }
Ejemplo n.º 3
0
        public override void ResetValue(object component)
        {
            object invocationTarget = this.GetInvocationTarget(this.componentClass, component);

            if (this.DefaultValue != noValue)
            {
                this.SetValue(component, this.DefaultValue);
            }
            else if (this.AmbientValue != noValue)
            {
                this.SetValue(component, this.AmbientValue);
            }
            else if (this.ResetMethodValue != null)
            {
                ISite site = MemberDescriptor.GetSite(component);
                IComponentChangeService service = null;
                object oldValue = null;
                if (site != null)
                {
                    service = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
                }
                if (service != null)
                {
                    oldValue = SecurityUtils.MethodInfoInvoke(this.GetMethodValue, invocationTarget, null);
                    try
                    {
                        service.OnComponentChanging(component, this);
                    }
                    catch (CheckoutException exception)
                    {
                        if (exception != CheckoutException.Canceled)
                        {
                            throw exception;
                        }
                        return;
                    }
                }
                if (this.ResetMethodValue != null)
                {
                    SecurityUtils.MethodInfoInvoke(this.ResetMethodValue, invocationTarget, null);
                    if (service != null)
                    {
                        object newValue = SecurityUtils.MethodInfoInvoke(this.GetMethodValue, invocationTarget, null);
                        service.OnComponentChanged(component, this, oldValue, newValue);
                    }
                }
            }
        }
 public override void RemoveEventHandler(object component, Delegate value)
 {
     this.FillMethods();
     if (component != null)
     {
         ISite site = MemberDescriptor.GetSite(component);
         IComponentChangeService service = null;
         if (site != null)
         {
             service = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
         }
         if (service != null)
         {
             try
             {
                 service.OnComponentChanging(component, this);
             }
             catch (CheckoutException exception)
             {
                 if (exception != CheckoutException.Canceled)
                 {
                     throw exception;
                 }
                 return;
             }
         }
         bool flag = false;
         if ((site != null) && site.DesignMode)
         {
             IDictionaryService service2 = (IDictionaryService)site.GetService(typeof(IDictionaryService));
             if (service2 != null)
             {
                 Delegate source = (Delegate)service2.GetValue(this);
                 source = Delegate.Remove(source, value);
                 service2.SetValue(this, source);
                 flag = true;
             }
         }
         if (!flag)
         {
             SecurityUtils.MethodInfoInvoke(this.removeMethod, component, new object[] { value });
         }
         if (service != null)
         {
             service.OnComponentChanged(component, this, null, value);
         }
     }
 }
Ejemplo n.º 5
0
 internal void ExtenderResetValue(IExtenderProvider provider, object component, PropertyDescriptor notifyDesc)
 {
     if (this.DefaultValue != noValue)
     {
         this.ExtenderSetValue(provider, component, this.DefaultValue, notifyDesc);
     }
     else if (this.AmbientValue != noValue)
     {
         this.ExtenderSetValue(provider, component, this.AmbientValue, notifyDesc);
     }
     else if (this.ResetMethodValue != null)
     {
         ISite site = MemberDescriptor.GetSite(component);
         IComponentChangeService service = null;
         object oldValue = null;
         if (site != null)
         {
             service = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
         }
         if (service != null)
         {
             oldValue = this.ExtenderGetValue(provider, component);
             try
             {
                 service.OnComponentChanging(component, notifyDesc);
             }
             catch (CheckoutException exception)
             {
                 if (exception != CheckoutException.Canceled)
                 {
                     throw exception;
                 }
                 return;
             }
         }
         provider = (IExtenderProvider)this.GetInvocationTarget(this.componentClass, provider);
         if (this.ResetMethodValue != null)
         {
             this.ResetMethodValue.Invoke(provider, new object[] { component });
             if (service != null)
             {
                 object newValue = this.ExtenderGetValue(provider, component);
                 service.OnComponentChanged(component, notifyDesc, oldValue, newValue);
             }
         }
     }
 }