|
System;
System.Collections.Generic;
System.Text;
System.ComponentModel;
PropertyGridEx
public class CustomPropertyCollection : List<CustomProperty>, ICustomTypeDescriptor
ICustomTypeDescriptor
public AttributeCollection GetAttributes()
return TypeDescriptor.GetAttributes(this, true);
public string GetClassName()
return TypeDescriptor.GetClassName(this, true);
public string GetComponentName()
return TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter()
return TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent()
return TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty()
return TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType)
return TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes)
return TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents()
return TypeDescriptor.GetEvents(this, true);
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);
foreach (CustomProperty cp in this)
List<Attribute> attrs = new List<Attribute>();
//[Browsable(false)]
if (!cp.IsBrowsable)
new BrowsableAttribute(cp.IsBrowsable));
//[ReadOnly(true)]
if (cp.IsReadOnly)
new ReadOnlyAttribute(cp.IsReadOnly));
//[Editor(typeof(editor),typeof(UITypeEditor))]
if (cp.EditorType != null)
new EditorAttribute(cp.EditorType, typeof(System.Drawing.Design.UITypeEditor)));
new CustomPropertyDescriptor(cp, attrs.ToArray()));
return properties;
public PropertyDescriptorCollection GetProperties()
return TypeDescriptor.GetProperties(this, true);
public object GetPropertyOwner(PropertyDescriptor pd)
return this;
Code Snippet
System;
System.Collections.Generic;
System.Text;
System.ComponentModel;
PropertyGridEx
public class CustomPropertyDescriptor : PropertyDescriptor
private CustomProperty _customProperty = null;
public CustomPropertyDescriptor(CustomProperty customProperty, Attribute[] attrs)
base(customProperty.Name, attrs)
public override bool CanResetValue(object component)
return _customProperty.DefaultValue != null;
public override Type ComponentType
get { return _customProperty.GetType(); }
public override object GetValue(object component)
return _customProperty.Value;
public override bool IsReadOnly
get { return _customProperty.IsReadOnly; }
public override Type PropertyType
get { return _customProperty.ValueType; }
public override void ResetValue(object component)
public override void SetValue(object component, object value)
public override bool ShouldSerializeValue(object component)
return true;
//
public override string Description
get
return _customProperty.Description;
public override string Category
get
return _customProperty.Category;
public override string DisplayName
get
return _customProperty.Name;
public override bool IsBrowsable
get
return _customProperty.IsBrowsable;
public object CustomProperty
get
return _customProperty;
Really hope this will help you!
Best regards,
TransformerYu
|