public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { if (value.GetType().Namespace == "System.ComponentModel.Design") { return(TypeDescriptor.GetProperties(value)); //var type = value.GetType(); //var valueField = type.GetField("value", BindingFlags.NonPublic | BindingFlags.Instance); //if (valueField != null) //{ // value = valueField.GetValue(value); //} } var fieldsArray = MyPropertyDescriptorForFields.CreateArray(value.GetType(), attributes); var propertiesArray = MyPropertyDescriptorForProperties.CreateArray(value.GetType(), attributes); return(new PropertyDescriptorCollection(propertiesArray.Concat <PropertyDescriptor>(fieldsArray).ToArray())); }
private static Attribute[] GetAttributes(PropertyInfo propertyInfo, IEnumerable <Attribute> defaultCustomAttributes) { var propertyAttributes = propertyInfo.GetCustomAttributes(true).OfType <Attribute>(); var attributes = MyPropertyDescriptorForFields.GetAttributes(propertyInfo.PropertyType, propertyAttributes.Concat(defaultCustomAttributes)); //var attributes = new List<Attribute>(); //attributes.AddRange(defaultCustomAttributes); //var customAttributes = propertyInfo.GetCustomAttributes(true); //attributes.AddRange(customAttributes.OfType<Attribute>()); ////var attributes = customAttributes.OfType<Attribute>().ToList(); //if (!NonExpandedTypes.Contains(propertyInfo.PropertyType) && // !propertyInfo.PropertyType.IsEnum) //{ // bool implementsIEnumerable = typeof(System.Collections.IEnumerable).IsAssignableFrom(propertyInfo.PropertyType); // if (!implementsIEnumerable) // { // attributes.Add(new TypeConverterAttribute(typeof(MyTypeConverter))); // } // attributes.AddRange(propertyInfo.GetCustomAttributes(true).OfType<Attribute>()); //} return(attributes); }
static Attribute[] GetAttributes(IList <T> array, int index) { return(MyPropertyDescriptorForFields.GetAttributes(typeof(T), new Attribute[0])); }