using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing.Design;
namespace Netron.Diagramming.Core
{
///
/// Represents the description of a property and is a transitional construction to the actual property descriptor of a property.
/// This class is a modification of the original idea presented by Tony Allowatt (http://www.codeproject.com/cs/miscctrl/bending_property.asp) and used in
/// a previous version of the graph library.
///
[Serializable] public class PropertySpec
{
#region Fields
private Attribute[] attributes;
private string category;
private object defaultValue;
private string description;
private string editor;
private string name;
private string type;
private string typeConverter;
#endregion
#region Properties
///
/// Gets or sets a collection of additional Attributes for this property. This can
/// be used to specify attributes beyond those supported intrinsically by the
/// PropertySpec class, such as ReadOnly and Browsable.
///
public Attribute[] Attributes
{
get { return attributes; }
set { attributes = value; }
}
///
/// Gets or sets the category name of this property.
///
public string Category
{
get { return category; }
set { category = value; }
}
///
/// Gets or sets the fully qualified name of the type converter
/// type for this property.
///
public string ConverterTypeName
{
get { return typeConverter; }
set { typeConverter = value; }
}
///
/// Gets or sets the default value of this property.
///
public object DefaultValue
{
get { return defaultValue; }
set { defaultValue = value; }
}
///
/// Gets or sets the help text description of this property.
///
public string Description
{
get { return description; }
set { description = value; }
}
///
/// Gets or sets the fully qualified name of the editor type for
/// this property.
///
public string EditorTypeName
{
get { return editor; }
set { editor = value; }
}
///
/// Gets or sets the name of this property.
///
public string Name
{
get { return name; }
set { name = value; }
}
///
/// Gets or sets the fully qualfied name of the type of this
/// property.
///
public string TypeName
{
get { return type; }
set { type = value; }
}
#endregion
#region Constructors
///
/// Initializes a new instance of the PropertySpec class.
///
/// The name of the property displayed in the property grid.
/// The fully qualified name of the type of the property.
public PropertySpec(string name, string type) : this(name, type, null, null, null) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// The name of the property displayed in the property grid.
/// A Type that represents the type of the property.
public PropertySpec(string name, Type type) :
this(name, type.AssemblyQualifiedName, null, null, null) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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 PropertySpec(string name, string type, string category) : this(name, type, category, null, null) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// The name of the property displayed in the property grid.
/// A Type that represents the type of the property.
///
public PropertySpec(string name, Type type, string category) :
this(name, type.AssemblyQualifiedName, category, null, null) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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 PropertySpec(string name, string type, string category, string description) :
this(name, type, category, description, null) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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.
public PropertySpec(string name, Type type, string category, string description) :
this(name, type.AssemblyQualifiedName, category, description, null) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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 PropertySpec(string name, string type, string category, string description, object defaultValue)
{
this.name = name;
this.type = type;
this.category = category;
this.description = description;
this.defaultValue = defaultValue;
this.attributes = null;
}
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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.
public PropertySpec(string name, Type type, string category, string description, object defaultValue) :
this(name, type.AssemblyQualifiedName, category, description, defaultValue) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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.
/// The fully qualified name of the type of the editor for this
/// property. This type must derive from UITypeEditor.
/// The fully qualified name of the type of the type
/// converter for this property. This type must derive from TypeConverter.
public PropertySpec(string name, string type, string category, string description, object defaultValue,
string editor, string typeConverter) : this(name, type, category, description, defaultValue)
{
this.editor = editor;
this.typeConverter = typeConverter;
}
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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 fully qualified name of the type of the editor for this
/// property. This type must derive from UITypeEditor.
/// The fully qualified name of the type of the type
/// converter for this property. This type must derive from TypeConverter.
public PropertySpec(string name, Type type, string category, string description, object defaultValue,
string editor, string typeConverter) :
this(name, type.AssemblyQualifiedName, category, description, defaultValue, editor, typeConverter) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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.
/// The Type that represents the type of the editor for this
/// property. This type must derive from UITypeEditor.
/// The fully qualified name of the type of the type
/// converter for this property. This type must derive from TypeConverter.
public PropertySpec(string name, string type, string category, string description, object defaultValue,
Type editor, string typeConverter) :
this(name, type, category, description, defaultValue, editor.AssemblyQualifiedName,
typeConverter) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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 fully qualified name of the type of the type
/// converter for this property. This type must derive from TypeConverter.
public PropertySpec(string name, Type type, string category, string description, object defaultValue,
Type editor, string typeConverter) :
this(name, type.AssemblyQualifiedName, category, description, defaultValue,
editor.AssemblyQualifiedName, typeConverter) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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.
/// The fully qualified name of 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 PropertySpec(string name, string type, string category, string description, object defaultValue,
string editor, Type typeConverter) :
this(name, type, category, description, defaultValue, editor, typeConverter.AssemblyQualifiedName) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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 fully qualified name of 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 PropertySpec(string name, Type type, string category, string description, object defaultValue,
string editor, Type typeConverter) :
this(name, type.AssemblyQualifiedName, category, description, defaultValue, editor,
typeConverter.AssemblyQualifiedName) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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.
/// 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 PropertySpec(string name, string type, string category, string description, object defaultValue,
Type editor, Type typeConverter) :
this(name, type, category, description, defaultValue, editor.AssemblyQualifiedName,
typeConverter.AssemblyQualifiedName) { }
///
/// Initializes a new instance of the PropertySpec class.
///
/// 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 PropertySpec(string name, Type type, string category, string description, object defaultValue,
Type editor, Type typeConverter) :
this(name, type.AssemblyQualifiedName, category, description, defaultValue,
editor.AssemblyQualifiedName, typeConverter.AssemblyQualifiedName) { }
#endregion
#region Methods
///
/// Converts this specification to an property descriptor.
///
///
internal PropertySpecDescriptor ToPropertyDescriptor()
{
ArrayList attrs = new ArrayList();
// If a category, description, editor, or type converter are specified
// in the thisSpec, create attributes to define that relationship.
if(this.Category != null)
attrs.Add(new CategoryAttribute(this.Category));
if(this.Description != null)
attrs.Add(new DescriptionAttribute(this.Description));
if(this.EditorTypeName != null)
attrs.Add(new EditorAttribute(this.EditorTypeName, typeof(UITypeEditor)));
if(this.ConverterTypeName != null)
attrs.Add(new TypeConverterAttribute(this.ConverterTypeName));
// Additionally, append the custom attributes associated with the
// thisSpec, if any.
if(this.Attributes != null)
attrs.AddRange(this.Attributes);
Attribute[] attrArray = (Attribute[]) attrs.ToArray(typeof(Attribute));
// Create a new this descriptor for the this item, and add
// it to the list.
return new PropertySpecDescriptor(this, attrArray);
}
#endregion
}
}