Exemplo n.º 1
0
        /// <summary>
        /// Returns the properties for this instance of a component using the attribute array as a filter.
        /// </summary>
        /// <param name="attributes">An array of type <see cref="Attribute"/> that is used as a filter.</param>
        /// <returns>An <see cref="PropertyDescriptorCollection"/> that represents the properties for this component instance that match the given set of attributes.</returns>
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this, attributes, true);
            ArrayList descriptors = new ArrayList(properties.Count);

            // Loop through the property descriptores that we got from the type descriptor to create
            // our own custom DisplayNamePropertyDescriptor objects that wrap the default descriptors.
            foreach (PropertyDescriptor property in properties)
            {
                PropertyGridPropertyDescriptor displayNameProperty = new PropertyGridPropertyDescriptor(property);
                descriptors.Add(displayNameProperty);
            }

            PropertyDescriptor[] array = (PropertyDescriptor[])descriptors.ToArray(typeof(PropertyDescriptor));
            return(new PropertyDescriptorCollection(array));
        }
        /// <summary>
        /// Returns the properties for this instance of a component using the attribute array as a filter.
        /// </summary>
        /// <param name="attributes">An array of type <see cref="Attribute"/> that is used as a filter.</param>
        /// <returns>An <see cref="PropertyDescriptorCollection"/> that represents the properties for this component instance that match the given set of attributes.</returns>
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this, attributes, true);
            ArrayList descriptors = new ArrayList(properties.Count);

            // Loop through the property descriptores that we got from the type descriptor to create
            // our own custom DisplayNamePropertyDescriptor objects that wrap the default descriptors.
            foreach (PropertyDescriptor property in properties)
            {
                PropertyGridPropertyDescriptor displayNameProperty = new PropertyGridPropertyDescriptor(property);
                descriptors.Add(displayNameProperty);
            }

            PropertyDescriptor[] array = (PropertyDescriptor[])descriptors.ToArray(typeof(PropertyDescriptor));
            return new PropertyDescriptorCollection(array);
        }