123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OTSModelSharp
- {
- public enum enumType
- {
- BOOLVAL,
- DIGITALVAL,
- STRINGVAL,
- CHECKVAL,
- RATIOVAL,
- IPVAL,
- COMBOBOX,
- RESETBTN
- };
- public class XProp
- {
- private string theId = ""; //属性Id,我的项目中需要,大家可以忽略
- private string theCategory = ""; //属性所属类别
- private string theName = ""; //属性名称
- private bool theReadOnly = false; //属性的只读性,true为只读
- private string theDescription = ""; //属性的描述内容
- private object theValue = null; //值
- private System.Type theType = null; //类型
- private bool theBrowsable = true; //显示或隐藏,true为显示
- TypeConverter theConverter = null; //类型转换 //Combobox
- private Color _color;
- private Font _font;
- // private string strdemo;
- public string Id
- {
- get { return theId; }
- set { theId = value; }
- }
- public string Category
- {
- get { return theCategory; }
- set { theCategory = value; }
- }
- public bool ReadOnly
- {
- get { return theReadOnly; }
- set { theReadOnly = value; }
- }
- public string Name
- {
- get { return this.theName; }
- set { this.theName = value; }
- }
- public object Value
- {
- get { return this.theValue; }
- set { this.theValue = value; }
- }
- public Color Color
- {
- get { return _color; }
- set { _color = value; }
- }
- public Font Font
- {
- get { return _font; }
- set { _font = value; }
- }
- public string Description
- {
- get { return theDescription; }
- set { theDescription = value; }
- }
- public System.Type ProType
- {
- get { return theType; }
- set { theType = value; }
- }
- public bool Browsable
- {
- get { return theBrowsable; }
- set { theBrowsable = value; }
- }
- public virtual TypeConverter Converter
- {
- get { return theConverter; }
- set { theConverter = value; }
- }
- }
- public class XProps : List<XProp>, ICustomTypeDescriptor
- {
- #region ICustomTypeDescriptor 成员
- public AttributeCollection GetAttributes()
- {
- return TypeDescriptor.GetAttributes(this, true);
- }
- public string GetClassName()
- {
- String strname = TypeDescriptor.GetClassName(this, true);
- return strname;
- }
- public string GetComponentName()
- {
- String CompnentName = TypeDescriptor.GetComponentName(this, true);
- return CompnentName;
- }
- 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(System.Type editorBaseType)
- {
- return TypeDescriptor.GetEditor(this, editorBaseType, true);
- }
- public EventDescriptorCollection GetEvents(System.Attribute[] attributes)
- {
- return TypeDescriptor.GetEvents(this, attributes, true);
- }
- public EventDescriptorCollection GetEvents()
- {
- return TypeDescriptor.GetEvents(this, true);
- }
- public PropertyDescriptorCollection GetProperties(System.Attribute[] attributes)
- {
- ArrayList props = new ArrayList();
- for (int i = 0; i < this.Count; i++)
- { //判断属性是否显示
- if (this[i].Browsable == true)
- {
- XPropDescriptor psd = new XPropDescriptor(this[i], attributes);
- props.Add(psd);
- }
- }
- PropertyDescriptor[] propArray = (PropertyDescriptor[])props.ToArray(typeof(PropertyDescriptor));
- return new PropertyDescriptorCollection(propArray);
- }
- public PropertyDescriptorCollection GetProperties()
- {
- return TypeDescriptor.GetProperties(this, true);
- }
- public object GetPropertyOwner(PropertyDescriptor pd)
- {
- return this;
- }
- #endregion
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < this.Count; i++)
- {
- sb.Append("[" + i + "] " + this[i].ToString() + System.Environment.NewLine);
- }
- return sb.ToString();
- }
- }
- public class XPropDescriptor : PropertyDescriptor
- {
- XProp theProp;
- public XPropDescriptor(XProp prop, Attribute[] attrs) : base(prop.Name, attrs)
- {
- theProp = prop;
- }
- public override bool CanResetValue(object component)
- {
- return false;
- }
- public override string Category
- {
- get { return theProp.Category; }
- }
- public override string Description
- {
- get { return theProp.Description; }
- }
- public override TypeConverter Converter
- {
- get { return theProp.Converter; }
- }
- public override System.Type ComponentType
- {
- get { return this.GetType(); }
- }
- public override object GetValue(object component)
- {
- return theProp.Value;
- }
- public override bool IsReadOnly
- {
- get { return theProp.ReadOnly; }
- }
- public override System.Type PropertyType
- {
- get { return theProp.ProType; }
- }
- public override void ResetValue(object component)
- {
- }
- public override void SetValue(object component, object value)
- {
- theProp.Value = value;
- }
- public override bool ShouldSerializeValue(object component)
- {
- return false;
- }
- }
- }
|