public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null); Options options = value as Options; if (options != null) { // Add Global options properties.Add(new OptionsPropertyDescriptor(options.Global, "Global", new CategoryAttribute(Category.Global), new DescriptionAttribute("Global options for the Kopano Outlook Extension.") )); // Add Features foreach (Acacia.Features.Feature feature in options.Features) { string description = "Shows the registry setting for the feature."; AcaciaOptionAttribute acacia = feature.GetType().GetCustomAttribute <AcaciaOptionAttribute>(); if (acacia != null) { description = acacia.Description; } properties.Add(new OptionsPropertyDescriptor(feature, feature.Name, new CategoryAttribute(Category.Features), new DescriptionAttribute(description) )); } } return(properties); }
/// <summary> /// Creates a grouping attributes /// </summary> /// <param name="obj"></param> public AcaciaPropertyDescriptor(object obj, string name) : base(name, new Attribute[0]) { this._obj = obj; this._acaciaAttr = null; this._orig = null; }
public AcaciaPropertyDescriptor(object obj, AcaciaOptionAttribute acaciaAttr, PropertyDescriptor orig) : base(orig) { this._obj = obj; this._acaciaAttr = acaciaAttr; this._orig = orig; }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection allProperties = TypeDescriptor.GetProperties(value); Dictionary <string, AcaciaPropertyDescriptor> properties = new Dictionary <string, AcaciaPropertyDescriptor>(); // Select all properties with AcaciaOptionAttribute and wrap those foreach (PropertyDescriptor pd in allProperties) { foreach (Attribute attr in pd.Attributes) { AcaciaOptionAttribute acaciaAttr = attr as AcaciaOptionAttribute; if (acaciaAttr != null) { // Check if it's supported if (acaciaAttr.Interface?.IsInstanceOfType(value) == false) { continue; } properties.Add(pd.Name, new AcaciaPropertyDescriptor(value, acaciaAttr, pd)); break; } } } // Group by name PropertyDescriptorCollection root = new PropertyDescriptorCollection(null); foreach (KeyValuePair <string, AcaciaPropertyDescriptor> entry in properties.ToArray()) { string[] nameParts = entry.Key.Split(new char[] { '_' }, 2); if (nameParts.Length == 2) { AcaciaPropertyDescriptor parent; if (!properties.ContainsKey(nameParts[0])) { // Add a grouping attribute parent = new AcaciaPropertyDescriptor(value, nameParts[0]); properties[nameParts[0]] = parent; root.Add(parent); } else { parent = properties[nameParts[0]]; } parent.MakeChild(entry.Value, nameParts[1]); } else { root.Add(entry.Value); } } return(root); }