Example #1
0
        private void ProcessProperties(PropertyInfo[] properties)
        {
            foreach (PropertyInfo property in properties)
            {
                List<Attribute> additionalAttributes = new List<Attribute>();

                #region determine if the property should be displayed
                BrowsableAttribute[] batt = property.GetCustomAttributes(typeof(BrowsableAttribute), true) as BrowsableAttribute[];
                if (batt == null || batt.Length == 0 || batt[0].Browsable == false)
                    continue; // skip the rest of the property processing
                additionalAttributes.Add(batt[0]);
                #endregion
                #region determine if the property has a friendly name
                string propertyName = property.Name;
                NameAttribute[] natt = property.GetCustomAttributes(typeof(NameAttribute), true) as NameAttribute[];
                if (natt != null && natt.Length > 0 && natt[0].Name != null && natt[0].Name.Length > 0)
                    propertyName = natt[0].Name;
                #endregion

                Type propertyType = property.PropertyType;
                string category = null, description = null, typeEditorName = null, typeConverterName = null;
                object defaultValue = null;
                bool isReadOnly = false;
                #region determine if the property is read-only
                MethodInfo miGetProp = property.GetGetMethod(true);
                MethodInfo miSetProp = property.GetSetMethod(true);
                if (miSetProp == null)
                {
                    ReadOnlyAttribute ro = new ReadOnlyAttribute(true);
                    isReadOnly = true;
                    additionalAttributes.Add(ro);
                }
                #endregion
                #region determine if it has a Category
                CategoryAttribute[] catt = property.GetCustomAttributes(typeof(CategoryAttribute), true) as CategoryAttribute[];
                if (catt != null && catt.Length > 0)
                    category = catt[0].Category;
                #endregion
                #region determine if it has a Description
                DescriptionAttribute[] datt = property.GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[];
                if (datt != null && datt.Length > 0)
                    description = datt[0].Description;
                #endregion
                #region determine if it has a default value
                DefaultValueAttribute[] dvatt = property.GetCustomAttributes(typeof(DefaultValueAttribute), true) as DefaultValueAttribute[];
                if (dvatt != null && dvatt.Length > 0)
                    defaultValue = dvatt[0].Value;
                #endregion
                #region determine if it has a type editor
                EditorAttribute[] eatt = property.GetCustomAttributes(typeof(EditorAttribute), true) as EditorAttribute[];
                if (eatt != null && eatt.Length > 0)
                    typeEditorName = eatt[0].EditorTypeName;
                #endregion
                #region determine if it has a type converter
                TypeConverterAttribute[] tcatt = property.GetCustomAttributes(typeof(TypeConverterAttribute), true) as TypeConverterAttribute[];
                if (tcatt != null && tcatt.Length > 0)
                    typeConverterName = tcatt[0].ConverterTypeName;
                #endregion

                List<Attribute> otherAttributes = CheckForAdditionalAttributes(property.GetCustomAttributes(true));

                additionalAttributes.AddRange(otherAttributes);

                PropertyDescriptorEx pdex = new PropertyDescriptorEx(propertyName, property.Name, category, defaultValue, description,
                    typeEditorName, typeConverterName, propertyType, isReadOnly, additionalAttributes.ToArray(), miGetProp, miSetProp, this);

                this.m_descriptors.Add(propertyName, pdex);
 
            }
        }
Example #2
0
        private void ProcessProperties(PropertyInfo[] properties)
        {
            foreach (PropertyInfo property in properties)
            {
                List <Attribute> additionalAttributes = new List <Attribute>();

                #region determine if the property should be displayed
                BrowsableAttribute[] batt = property.GetCustomAttributes(typeof(BrowsableAttribute), true) as BrowsableAttribute[];
                if (batt == null || batt.Length == 0 || batt[0].Browsable == false)
                {
                    continue; // skip the rest of the property processing
                }
                additionalAttributes.Add(batt[0]);
                #endregion
                #region determine if the property has a friendly name
                string          propertyName = property.Name;
                NameAttribute[] natt         = property.GetCustomAttributes(typeof(NameAttribute), true) as NameAttribute[];
                if (natt != null && natt.Length > 0 && natt[0].Name != null && natt[0].Name.Length > 0)
                {
                    propertyName = natt[0].Name;
                }
                #endregion

                Type   propertyType = property.PropertyType;
                string category = null, description = null, typeEditorName = null, typeConverterName = null;
                object defaultValue = null;
                bool   isReadOnly   = false;
                #region determine if the property is read-only
                MethodInfo miGetProp = property.GetGetMethod(true);
                MethodInfo miSetProp = property.GetSetMethod(true);
                if (miSetProp == null)
                {
                    ReadOnlyAttribute ro = new ReadOnlyAttribute(true);
                    isReadOnly = true;
                    additionalAttributes.Add(ro);
                }
                #endregion
                #region determine if it has a Category
                CategoryAttribute[] catt = property.GetCustomAttributes(typeof(CategoryAttribute), true) as CategoryAttribute[];
                if (catt != null && catt.Length > 0)
                {
                    category = catt[0].Category;
                }
                #endregion
                #region determine if it has a Description
                DescriptionAttribute[] datt = property.GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[];
                if (datt != null && datt.Length > 0)
                {
                    description = datt[0].Description;
                }
                #endregion
                #region determine if it has a default value
                DefaultValueAttribute[] dvatt = property.GetCustomAttributes(typeof(DefaultValueAttribute), true) as DefaultValueAttribute[];
                if (dvatt != null && dvatt.Length > 0)
                {
                    defaultValue = dvatt[0].Value;
                }
                #endregion
                #region determine if it has a type editor
                EditorAttribute[] eatt = property.GetCustomAttributes(typeof(EditorAttribute), true) as EditorAttribute[];
                if (eatt != null && eatt.Length > 0)
                {
                    typeEditorName = eatt[0].EditorTypeName;
                }
                #endregion
                #region determine if it has a type converter
                TypeConverterAttribute[] tcatt = property.GetCustomAttributes(typeof(TypeConverterAttribute), true) as TypeConverterAttribute[];
                if (tcatt != null && tcatt.Length > 0)
                {
                    typeConverterName = tcatt[0].ConverterTypeName;
                }
                #endregion

                List <Attribute> otherAttributes = CheckForAdditionalAttributes(property.GetCustomAttributes(true));

                additionalAttributes.AddRange(otherAttributes);

                PropertyDescriptorEx pdex = new PropertyDescriptorEx(propertyName, property.Name, category, defaultValue, description,
                                                                     typeEditorName, typeConverterName, propertyType, isReadOnly, additionalAttributes.ToArray(), miGetProp, miSetProp, this);

                this.m_descriptors.Add(propertyName, pdex);
            }
        }