System.ComponentModel.PropertyDescriptorCollection.RemoveAt C# (CSharp) Метод

RemoveAt() публичный Метод

public RemoveAt ( int index ) : void
index int
Результат void
        public void RemoveAt(int index) {
            if (readOnly) {
                throw new NotSupportedException();
            }

            if (index < propCount - 1) {
                Array.Copy(properties, index + 1, properties, index, propCount - index - 1);
            }
            properties[propCount - 1] = null;
            propCount--;
        }

Usage Example

        /// <summary>
        /// This is overridden to return a property descriptors for the object represented by this type
        /// descriptor along with extra property descriptors for its child properties.
        /// </summary>
        /// <param name="attributes">An array of attributes to use as a filter or null for no filter</param>
        /// <returns>Returns a <see cref="PropertyDescriptorCollection"/> that contains property descriptors for
        /// the object and its child properties.</returns>
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            // This seems to ignore the filter so GetChildProperties() will get rid of all non-browsable
            // properties.
            PropertyDescriptorCollection props = base.GetProperties(attributes);
            List<PropertyDescriptor> newProps = new List<PropertyDescriptor>();

            this.GetChildProperties(null, String.Empty, attributes, props, newProps);

            if(newProps.Count != 0)
            {
                // The collection is read-only so we'll need to create a new one
                PropertyDescriptor[] tempProps = new PropertyDescriptor[props.Count + newProps.Count];

                props.CopyTo(tempProps, 0);
                newProps.CopyTo(tempProps, props.Count);

                props = new PropertyDescriptorCollection(tempProps);

                // Now we'll remove hidden top-level properties
                for(int idx = 0; idx < props.Count; idx++)
                    if(props[idx].Attributes[typeof(HidePropertyAttribute)] != null)
                    {
                        props.RemoveAt(idx);
                        idx--;
                    }
            }

            return props;
        }
All Usage Examples Of System.ComponentModel.PropertyDescriptorCollection::RemoveAt