Пример #1
0
 void IContainer.Add(IComponent component, string name)
 {
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     DesignSite site = this._newComponentSite;
     this._newComponentSite = null;
     if (name == null)
     {
         if (site != null)
         {
             name = site.Name;
         }
         else
         {
             name = this.GetNewComponentName(component.GetType());
         }
     }
     ISite site2 = component.Site;
     if (((site2 != null) && (site2.Container == this)) && ((name != null) && !name.Equals(site2.Name)))
     {
         site2.Name = name;
     }
     if (!this.IsValidComponentName(name))
     {
         throw new ArgumentException("'" + name + "' is not a valid name");
     }
     if (this.ComponentTable[name] != null)
     {
         throw new ArgumentException("Component with name '" + name + "' already exists");
     }
     if (site2 != null)
     {
         site2.Container.Remove(component);
     }
     ComponentEventArgs e = new ComponentEventArgs(component);
     this.OnComponentAdding(e);
     if (site == null)
     {
         IServiceProvider serviceProvider = null;
         if (this.ActiveLayer != null)
         {
             serviceProvider = this.ActiveLayer;
         }
         else
         {
             serviceProvider = this;
         }
         site = new DesignSite(serviceProvider, name);
     }
     else
     {
         site.Name = name;
     }
     bool flag = true;
     Type designerType = typeof(IDesigner);
     if ((this._documentComponent != null) && (this._rootComponent == null))
     {
         designerType = typeof(IRootDesigner);
     }
     IDesigner designer = this.CreateComponentDesigner(component, designerType);
     if (designer == null)
     {
         throw new Exception("Unable to create a designer for component of type " + component.GetType().FullName);
     }
     if ((this._documentComponent == null) && name.Equals(this.DocumentComponentName))
     {
         this._documentComponent = component;
         this._documentDesigner = designer;
         flag = false;
     }
     else if (this._rootComponent == null)
     {
         this._rootComponent = component;
         this._rootDesigner = designer;
         flag = false;
     }
     this.HasClearableComponents |= flag;
     site.SetComponent(component);
     component.Site = site;
     this.ComponentTable[name] = component;
     designer.Initialize(component);
     this.DesignerTable[component] = designer;
     this.OnComponentAdded(e);
 }
Пример #2
0
 IComponent IDesignerHost.CreateComponent(Type componentType, string name)
 {
     if (componentType == null)
     {
         throw new ArgumentNullException("componentType");
     }
     object obj2 = null;
     IComponent component = null;
     IServiceProvider serviceProvider = null;
     if (this.ActiveLayer != null)
     {
         serviceProvider = this.ActiveLayer;
     }
     else
     {
         serviceProvider = this;
     }
     this._newComponentSite = new DesignSite(serviceProvider, name);
     try
     {
         try
         {
             object[] args = new object[] { this };
             Type[] argTypes = new Type[] { typeof(IContainer) };
             obj2 = this.CreateObject(componentType, args, argTypes);
         }
         catch
         {
         }
         if (obj2 == null)
         {
             obj2 = this.CreateObject(componentType, null, null);
         }
         component = obj2 as IComponent;
         if (component == null)
         {
             throw new ArgumentException(componentType.FullName + " is not an IComponent");
         }
         if (!(component.Site is DesignSite))
         {
             ((IContainer) this).Add(component);
         }
     }
     catch
     {
         if (component != null)
         {
             try
             {
                 ((IDesignerHost) this).DestroyComponent(component);
             }
             catch
             {
             }
         }
         this._newComponentSite = null;
         throw;
     }
     return component;
 }
Пример #3
0
 internal void RenameComponent(DesignSite site, string newName)
 {
     if (!this.IsValidComponentName(newName))
     {
         throw new ArgumentException("'" + newName + "' is not a valid name for the component.");
     }
     if (this.ComponentTable[newName] != null)
     {
         throw new ArgumentException("A component with the name '" + newName + "' already exists.");
     }
     string name = site.Name;
     ComponentRenameEventArgs e = new ComponentRenameEventArgs(site.Component, name, newName);
     this.ComponentTable.Remove(name);
     this.ComponentTable[newName] = site.Component;
     site.SetName(newName);
     this.OnComponentRename(e);
 }