Exemplo n.º 1
0
        /// <summary>
        ///     Validates that the given name is valid for a component.  The default implementation
        ///     verifies that name is either null or unique compared to the names of other
        ///     components in the container.
        /// </summary>
        protected virtual void ValidateName(IComponent component, string name)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            if (name != null)
            {
                for (int i = 0; i < Math.Min(_siteCount, _sites.Length); i++)
                {
                    ISite s = _sites[i];

                    if (s != null && s.Name != null &&
                        string.Equals(s.Name, name, StringComparison.OrdinalIgnoreCase) &&
                        s.Component != component)
                    {
                        InheritanceAttribute inheritanceAttribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(s.Component)[typeof(InheritanceAttribute)];
                        if (inheritanceAttribute.InheritanceLevel != InheritanceLevel.InheritedReadOnly)
                        {
                            throw new ArgumentException(SR.Format(SR.DuplicateComponentName, name));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 protected virtual void PostFilterAttributes(IDictionary attributes)
 {
     if (attributes.Contains(typeof(System.ComponentModel.InheritanceAttribute)))
     {
         this.inheritanceAttribute = attributes[typeof(System.ComponentModel.InheritanceAttribute)] as System.ComponentModel.InheritanceAttribute;
     }
     else if (!this.InheritanceAttribute.Equals(System.ComponentModel.InheritanceAttribute.NotInherited))
     {
         attributes[typeof(System.ComponentModel.InheritanceAttribute)] = this.InheritanceAttribute;
     }
 }
 protected virtual void ValidateName(IComponent component, string name)
 {
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     if (name != null)
     {
         for (int i = 0; i < Math.Min(this.siteCount, this.sites.Length); i++)
         {
             ISite site = this.sites[i];
             if (((site != null) && (site.Name != null)) && (string.Equals(site.Name, name, StringComparison.OrdinalIgnoreCase) && (site.Component != component)))
             {
                 InheritanceAttribute attribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(site.Component)[typeof(InheritanceAttribute)];
                 if (attribute.InheritanceLevel != InheritanceLevel.InheritedReadOnly)
                 {
                     throw new ArgumentException(SR.GetString("DuplicateComponentName", new object[] { name }));
                 }
             }
         }
     }
 }
 protected virtual void PostFilterAttributes(IDictionary attributes)
 {
     if (attributes.Contains(typeof(System.ComponentModel.InheritanceAttribute)))
     {
         this.inheritanceAttribute = attributes[typeof(System.ComponentModel.InheritanceAttribute)] as System.ComponentModel.InheritanceAttribute;
     }
     else if (!this.InheritanceAttribute.Equals(System.ComponentModel.InheritanceAttribute.NotInherited))
     {
         attributes[typeof(System.ComponentModel.InheritanceAttribute)] = this.InheritanceAttribute;
     }
 }
 public TrayControl(ComponentTray tray, IComponent component)
 {
     this.tray = tray;
     this.component = component;
     base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
     base.SetStyle(ControlStyles.Selectable, false);
     this.borderWidth = SystemInformation.BorderSize.Width;
     this.UpdateIconInfo();
     IComponentChangeService service = (IComponentChangeService) tray.GetService(typeof(IComponentChangeService));
     bool enabled = System.ComponentModel.CompModSwitches.CommonDesignerServices.Enabled;
     if (service != null)
     {
         service.ComponentRename += new ComponentRenameEventHandler(this.OnComponentRename);
     }
     ISite site = component.Site;
     string name = null;
     if (site != null)
     {
         name = site.Name;
         IDictionaryService service2 = (IDictionaryService) site.GetService(typeof(IDictionaryService));
         if (service2 != null)
         {
             service2.SetValue(base.GetType(), this);
         }
     }
     if (name == null)
     {
         name = component.GetType().Name;
     }
     this.Text = name;
     this.inheritanceAttribute = (System.ComponentModel.InheritanceAttribute) TypeDescriptor.GetAttributes(component)[typeof(System.ComponentModel.InheritanceAttribute)];
     base.TabStop = false;
 }
 protected virtual void AddInheritedComponents(Type type, IComponent component, IContainer container)
 {
     if ((type != null) && typeof(IComponent).IsAssignableFrom(type))
     {
         ISite site = component.Site;
         IComponentChangeService service = null;
         INameCreationService service2 = null;
         if (site != null)
         {
             service2 = (INameCreationService) site.GetService(typeof(INameCreationService));
             service = (IComponentChangeService) site.GetService(typeof(IComponentChangeService));
             if (service != null)
             {
                 service.ComponentAdding += new ComponentEventHandler(this.OnComponentAdding);
             }
         }
         try
         {
             while (type != typeof(object))
             {
                 Type reflectionType = TypeDescriptor.GetReflectionType(type);
                 foreach (FieldInfo info in reflectionType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                 {
                     string name = info.Name;
                     Type reflectionTypeFromTypeHelper = GetReflectionTypeFromTypeHelper(info.FieldType);
                     if (GetReflectionTypeFromTypeHelper(typeof(IComponent)).IsAssignableFrom(reflectionTypeFromTypeHelper))
                     {
                         object obj2 = info.GetValue(component);
                         if (obj2 != null)
                         {
                             InheritanceAttribute inheritedReadOnly;
                             MemberInfo member = info;
                             object[] customAttributes = info.GetCustomAttributes(typeof(AccessedThroughPropertyAttribute), false);
                             if ((customAttributes != null) && (customAttributes.Length > 0))
                             {
                                 AccessedThroughPropertyAttribute attribute = (AccessedThroughPropertyAttribute) customAttributes[0];
                                 PropertyInfo property = reflectionType.GetProperty(attribute.PropertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                                 if ((property != null) && (property.PropertyType == info.FieldType))
                                 {
                                     if (!property.CanRead)
                                     {
                                         continue;
                                     }
                                     member = property.GetGetMethod(true);
                                     name = attribute.PropertyName;
                                 }
                             }
                             bool flag = this.IgnoreInheritedMember(member, component);
                             bool flag2 = false;
                             if (flag)
                             {
                                 flag2 = true;
                             }
                             else if (member is FieldInfo)
                             {
                                 FieldInfo info4 = (FieldInfo) member;
                                 flag2 = info4.IsPrivate | info4.IsAssembly;
                             }
                             else if (member is MethodInfo)
                             {
                                 MethodInfo info5 = (MethodInfo) member;
                                 flag2 = info5.IsPrivate | info5.IsAssembly;
                             }
                             if (flag2)
                             {
                                 inheritedReadOnly = InheritanceAttribute.InheritedReadOnly;
                             }
                             else
                             {
                                 inheritedReadOnly = InheritanceAttribute.Inherited;
                             }
                             bool flag3 = this.inheritedComponents[obj2] == null;
                             this.inheritedComponents[obj2] = inheritedReadOnly;
                             if (!flag && flag3)
                             {
                                 try
                                 {
                                     this.addingComponent = (IComponent) obj2;
                                     this.addingAttribute = inheritedReadOnly;
                                     if ((service2 == null) || service2.IsValidName(name))
                                     {
                                         try
                                         {
                                             container.Add((IComponent) obj2, name);
                                         }
                                         catch
                                         {
                                         }
                                     }
                                 }
                                 finally
                                 {
                                     this.addingComponent = null;
                                     this.addingAttribute = null;
                                 }
                             }
                         }
                     }
                 }
                 type = type.BaseType;
             }
         }
         finally
         {
             if (service != null)
             {
                 service.ComponentAdding -= new ComponentEventHandler(this.OnComponentAdding);
             }
         }
     }
 }