当前位置: 首页>>代码示例>>C#>>正文


C# IComponent.Dispose方法代码示例

本文整理汇总了C#中IComponent.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IComponent.Dispose方法的具体用法?C# IComponent.Dispose怎么用?C# IComponent.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IComponent的用法示例。


在下文中一共展示了IComponent.Dispose方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Remove

        public void Remove(IComponent component)
        {
            if(component==null)
            {
                throw new ArgumentException("component");
            }
            // fire off changing and removing event
            ComponentEventArgs ce = new ComponentEventArgs(component);
            OnComponentChanging(component,null);
            try
            {
                if(ComponentRemoving!=null)
                {
                    ComponentRemoving(this, ce);
                }
            }
            catch
            {
                // dont throw here
            }
            // make sure we own the component
            if(component.Site!=null && component.Site.Container==this)
            {
                // remove from extender provider list
                if (component is IExtenderProvider)
                {
                    IExtenderProviderService extenderProvider = (IExtenderProviderService)GetService(typeof(IExtenderProviderService));
                    if(extenderProvider!=null)
                    {
                        extenderProvider.RemoveExtenderProvider((IExtenderProvider)component);
                    }
                }
                // remove the site
                sites.Remove(component.Site.Name);
                // dispose the designer
                IDesigner designer = designers[component] as IDesigner;
                if(designer!=null)
                {
                    designer.Dispose();
                    // get rid of the designer from the list
                    designers.Remove(component);
                }

                // fire off removed event
                try
                {
                    if(ComponentRemoved!=null)
                    {
                        ComponentRemoved(this, ce);
                    }
                    this.OnComponentChanged(component,null,null,null);
                }
                catch
                {
                    // dont throw here
                }

                // breakdown component, container, and site relationship
                component.Site=null;

                // now dispose the of the component too
                component.Dispose();
            }
        }
开发者ID:puentepr,项目名称:thuctapvietinsoft,代码行数:64,代码来源:DesignerHostImpl.cs

示例2: DestroyComponent

		public void DestroyComponent (IComponent component)
		{
			if (component.Site != null && component.Site.Container == this) {
				OnComponentChanging (component, null);
				
				this.Remove (component); // takes care for the designer as well
				component.Dispose ();

				OnComponentChanged (component, null, null, null);
			}
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:11,代码来源:DesignerHost.cs

示例3: ArgumentNullException

 void IContainer.Remove(IComponent component)
 {
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     if (component.Site != null)
     {
         string name = component.Site.Name;
         if ((name != null) && (this.ComponentTable[name] == component))
         {
             ComponentEventArgs e = new ComponentEventArgs(component);
             this.OnComponentRemoving(e);
             if (this.DesignerTable != null)
             {
                 IDesigner designer = (IDesigner) this.DesignerTable[component];
                 if (designer != null)
                 {
                     this.DesignerTable.Remove(component);
                     designer.Dispose();
                 }
             }
             this.ComponentTable.Remove(name);
             component.Dispose();
             try
             {
                 this.OnComponentRemoved(e);
             }
             catch
             {
             }
             component.Site = null;
         }
     }
 }
开发者ID:ikvm,项目名称:webmatrix,代码行数:35,代码来源:DesignerHost.cs

示例4: ArgumentNullException

 void IDesignerHost.DestroyComponent(IComponent component)
 {
     string name;
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     if ((component.Site != null) && (component.Site.Name != null))
     {
         name = component.Site.Name;
     }
     else
     {
         name = component.GetType().Name;
     }
     InheritanceAttribute attribute = (InheritanceAttribute) TypeDescriptor.GetAttributes(component)[typeof(InheritanceAttribute)];
     if ((attribute != null) && (attribute.InheritanceLevel != InheritanceLevel.NotInherited))
     {
         Exception exception = new InvalidOperationException(System.Design.SR.GetString("DesignerHostCantDestroyInheritedComponent", new object[] { name })) {
             HelpLink = "DesignerHostCantDestroyInheritedComponent"
         };
         throw exception;
     }
     if (((IDesignerHost) this).InTransaction)
     {
         this.Remove(component);
         component.Dispose();
     }
     else
     {
         using (DesignerTransaction transaction = ((IDesignerHost) this).CreateTransaction(System.Design.SR.GetString("DesignerHostDestroyComponentTransaction", new object[] { name })))
         {
             this.Remove(component);
             component.Dispose();
             transaction.Commit();
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:38,代码来源:DesignerHost.cs

示例5: DestroyComponent

        ///     Destroys the given component, removing it from the design container.
        public void DestroyComponent(IComponent comp) {
            string name;
            
            if (comp.Site != null && comp.Site.Name != null) {
                name = comp.Site.Name;
            }
            else {
                name = comp.GetType().Name;
            }

            // Make sure the component is not being inherited -- we can't delete these!
            InheritanceAttribute ia = (InheritanceAttribute)TypeDescriptor.GetAttributes(comp)[typeof(InheritanceAttribute)];
            if (ia != null && ia.InheritanceLevel != InheritanceLevel.NotInherited) {
                throw new InvalidOperationException("CantDestroyInheritedComponent" + name);
            }
            
            DesignerTransaction t = null;
            try {
                // We try to remove the component from the container before destroying it.  
                t = CreateTransaction("DestroyComponentTransaction" + name);

                // We need to signal changing and then perform the remove.  Remove must be done by us and not
                // by Dispose because (a) people need a chance to cancel through a Removing event, and (b)
                // Dispose removes from the container last and anything that would sync Removed would end up
                // with a dead component.
                //
                ((IComponentChangeService)this).OnComponentChanging(comp, null);
                if (comp.Site != null) {
                    Remove(comp);
                }
                DeleteDesignedComponent(comp);
                comp.Dispose();
                ((IComponentChangeService)this).OnComponentChanged(comp, null, null, null);
            }
            finally {
                if (t != null) {
                    t.Commit();
                }
            }
        }
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:41,代码来源:SampleDesignerHost.cs

示例6: DestroyComponent

		public void DestroyComponent (IComponent component)
		{
				this.Remove (component); // takes care of the designer as well
				component.Dispose ();
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:5,代码来源:DesignerHost.cs

示例7: DestroyComponent

		public void DestroyComponent (IComponent component)
		{
			//deselect it if selected
			ISelectionService sel = this.GetService (typeof (ISelectionService)) as ISelectionService;
			bool found = false;
			if (sel != null)
				foreach (IComponent c in sel.GetSelectedComponents ())
					if (c == component) {
						found = true;
						break;
					}
			//can't modify selection in loop
			if (found) sel.SetSelectedComponents (null);
						
			if (component != RootComponent) {
				//remove from component and document
				((Control) RootComponent).Controls.Remove ((Control) component);
				RootDocument.RemoveControl ((Control)component);
			}

			//remove from container if still sited
			if (component.Site != null)
				container.Remove (component);
			
			component.Dispose ();
		}
开发者ID:segaman,项目名称:monodevelop,代码行数:26,代码来源:DesignerHost.cs

示例8: DestroyComponent

 public void DestroyComponent(IComponent comp)
 {
     string name;
     if ((comp.Site != null) && (comp.Site.Name != null))
     {
         name = comp.Site.Name;
     }
     else
     {
         name = comp.GetType().Name;
     }
     InheritanceAttribute ia = (InheritanceAttribute) TypeDescriptor.GetAttributes(comp)[typeof(InheritanceAttribute)];
     if ((ia != null) && (ia.InheritanceLevel != InheritanceLevel.NotInherited))
     {
         throw new InvalidOperationException("CantDestroyInheritedComponent" + name);
     }
     DesignerTransaction t = null;
     try
     {
         t = this.CreateTransaction("DestroyComponentTransaction" + name);
         ((IComponentChangeService) this).OnComponentChanging(comp, null);
         if (comp.Site != null)
         {
             this.Remove(comp);
         }
         comp.Dispose();
         ((IComponentChangeService) this).OnComponentChanged(comp, null, null, null);
     }
     finally
     {
         if (t != null)
         {
             t.Commit();
         }
     }
 }
开发者ID:MuffPotter,项目名称:XamarinDesigner,代码行数:36,代码来源:SampleDesignerHost.cs


注:本文中的IComponent.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。