System.ComponentModel.Container.ValidateName C# (CSharp) Method

ValidateName() protected method

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.
protected ValidateName ( IComponent component, string name ) : void
component IComponent
name string
return void
        protected virtual void ValidateName(IComponent component, string name)
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(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));
                        }
                    }
                }
            }
        }