void IContainer.Add(IComponent component, string name) { if (null != component) { if ((this.rootComponent != null) && (string.Compare(component.GetType().FullName, this.rootComponentClassName, true) == 0)) { Exception ex = new Exception("Can't add a component to itself " + component.GetType().FullName); throw ex; } ISite site = component.Site; if ((site != null) && (site.Container == this)) { if ((name != null) && !name.Equals(site.Name)) { try { this.CheckName(name); } catch (Exception) { name = this.GetNewComponentName(site.GetType()); site.Name = name; } site.Name = name; } } else { SampleDesignSite newSite = this.newComponentSite; this.newComponentSite = null; if ((newSite != null) && (name == null)) { name = newSite.Name; } if ((name != null) && !this.CheckName(name)) { } ComponentEventArgs ce = new ComponentEventArgs(component); this.OnComponentAdding(ce); if (site != null) { site.Container.Remove(component); } if (newSite == null) { newSite = new SampleDesignSite(this, name); } if (this.components[name] != null) { name = this.GetNewComponentName(component.GetType()); newSite.Name = name; } newSite.SetComponent(component); Debug.Assert((name == null) || name.Equals(newSite.Name), "Name should match the one in newComponentSite"); if (!(!(component is IExtenderProvider) || TypeDescriptor.GetAttributes(component).Contains(InheritanceAttribute.InheritedReadOnly))) { ((IExtenderProviderService)this).AddExtenderProvider((IExtenderProvider)component); } this.sites[newSite.Name] = newSite; component.Site = newSite; if (this.components != null) { this.components.Add(newSite); } try { this.CreateComponentDesigner(component); this.OnComponentAdded(ce); } catch (Exception) { if (!this.loadingDesigner) { ((IContainer)this).Remove(component); } throw; } } } }