using System;
using System.ComponentModel;
namespace Netron.Diagramming.Core {
///
/// Abstract base class for custom descriptors based on our properties mechanism.
///
/// Usually you do not inherit from this class to describe properties of entities, use the appropriate
/// specializations like the or classes instead.
/// Also, this class does not define any properties for the property grid but contains methods and basic stuff to make the construction of
/// concrete descriptors easier.
///
///
abstract class DescriptorBase : CustomTypeDescriptor {
#region Fields
//the provider to which this descriptor is attached
private TypeDescriptionProvider provider;
///
/// the type being served
///
private Type type;
///
/// the collection of properties displayed
///
private PropertyDescriptorCollection mProperties;
#endregion
#region Properties
///
/// Gets the collection of property descrtiptors
///
protected PropertyDescriptorCollection Properties {
get { return mProperties; }
}
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The provider.
/// The parentdescriptor.
/// Type of the object.
public DescriptorBase(ShapeProvider provider, ICustomTypeDescriptor parentdescriptor, Type objectType)
: base(parentdescriptor) {
this.provider = provider;
this.type = objectType;
mProperties = new PropertyDescriptorCollection(null);
}
///
/// Initializes a new instance of the class.
///
/// The provider.
/// Type of the object.
public DescriptorBase(TypeDescriptionProvider provider, Type objectType)
: base() {
this.provider = provider;
this.type = objectType;
mProperties = new PropertyDescriptorCollection(null);
}
#endregion
#region Methods
#region AddProperty overloads
///
/// Adds a new property to the property descriptor collection.
///
/// The name of the property displayed in the property grid.
/// The fully qualified name of the type of the property.
public void AddProperty(string name, Type type) {
PropertySpec widthSpec = new PropertySpec(name, type);
PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
pd.OnGetValue += new EventHandler(GetValue);
pd.OnSetValue += new EventHandler(SetValue);
mProperties.Add(pd);
}
///
/// Adds a new property to the property descriptor collection.
///
/// The name of the property displayed in the property grid.
/// The fully qualified name of the type of the property.
/// The category under which the property is displayed in the
/// property grid.
public void AddProperty(string name, Type type, string category) {
PropertySpec widthSpec = new PropertySpec(name, type, category);
PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
pd.OnGetValue += new EventHandler(GetValue);
pd.OnSetValue += new EventHandler(SetValue);
mProperties.Add(pd);
}
///
/// Adds a new property to the property descriptor collection.
///
/// The name of the property displayed in the property grid.
/// The fully qualified name of the type of the property.
/// The category under which the property is displayed in the
/// property grid.
/// A string that is displayed in the help area of the
/// property grid.
public void AddProperty(string name, Type type, string category, string description) {
PropertySpec widthSpec = new PropertySpec(name, type, category, description);
PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
pd.OnGetValue += new EventHandler(GetValue);
pd.OnSetValue += new EventHandler(SetValue);
mProperties.Add(pd);
}
///
/// Adds a new property to the property descriptor collection.
///
/// The name of the property displayed in the property grid.
/// The fully qualified name of the type of the property.
/// The category under which the property is displayed in the
/// property grid.
/// A string that is displayed in the help area of the
/// property grid.
/// The default value of the property, or null if there is
/// no default value.
public void AddProperty(string name, Type type, string category, string description, object defaultValue) {
PropertySpec widthSpec = new PropertySpec(name, type, category, description, defaultValue);
PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
pd.OnGetValue += new EventHandler(GetValue);
pd.OnSetValue += new EventHandler(SetValue);
mProperties.Add(pd);
}
///
/// Adds a new property to the property descriptor collection.
///
/// The name of the property displayed in the property grid.
/// A Type that represents the type of the property.
/// The category under which the property is displayed in the
/// property grid.
/// A string that is displayed in the help area of the
/// property grid.
/// The default value of the property, or null if there is
/// no default value.
/// The Type that represents the type of the editor for this
/// property. This type must derive from UITypeEditor.
/// The Type that represents the type of the type
/// converter for this property. This type must derive from TypeConverter.
public void AddProperty(string name, Type type, string category, string description, object defaultValue, Type editor, Type typeConverter) {
PropertySpec widthSpec = new PropertySpec(name, type, category, description, defaultValue, editor, typeConverter);
PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
pd.OnGetValue += new EventHandler(GetValue);
pd.OnSetValue += new EventHandler(SetValue);
mProperties.Add(pd);
}
#endregion
///
/// Overrides the method to retun the collection of properties we defined internally
///
///
///
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) {
return mProperties;
}
///
/// Returns a collection of property descriptors for the object represented by this type descriptor.
///
///
/// A containing the property descriptions for the object represented by this type descriptor. The default is .
///
public override PropertyDescriptorCollection GetProperties() {
return GetProperties(null);
}
///
/// Override this method to return the appropriate value corresponding to the property
///
///
///
protected virtual void GetValue(object sender, PropertyEventArgs e) {
}
///
/// Override this method to set the appropriate value corresponding to the property
///
///
///
protected virtual void SetValue(object sender, PropertyEventArgs e) {
}
#endregion
}
}