123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- namespace FWindSoft.WinForm
- {
- /// <summary>
- /// 属性窗格绑定类
- /// </summary>
- public class PropertyCollection : Collection<PropertyItem>, ICustomTypeDescriptor
- {
- public PropertyCollection() : base()
- {
- }
- protected override void ClearItems()
- {
- foreach (var propertyItem in this)
- {
- propertyItem.Owner = null;
- }
- base.ClearItems();
- }
- protected override void InsertItem(int index, PropertyItem item)
- {
- if (item == null)
- return;
- this[index].Owner = this;
- base.InsertItem(index, item);
- }
- protected override void RemoveItem(int index)
- {
- this[index].Owner = null;
- base.RemoveItem(index);
- }
- protected override void SetItem(int index, PropertyItem item)
- {
- item.Owner = this;
- this[index].Owner = null;
- base.SetItem(index, item);
- }
- public PropertyItem this[string name]
- {
- get
- {
- return this.FirstOrDefault(t=> t != null && t.Name == name);
- }
- }
- #region 实现接口
- 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)
- {
- ArrayList props = new ArrayList();
- for (int i = 0; i < this.Count; i++)
- {
- //判断属性是否显示
- if (this[i].IsVisible)
- {
- PropDescriptor psd = new PropDescriptor(this[i], attributes);
- props.Add(psd);
- }
- }
- PropertyDescriptor[] propArray = (PropertyDescriptor[])props.ToArray(typeof(PropDescriptor));
- return new PropertyDescriptorCollection(propArray);
- }
- public PropertyDescriptorCollection GetProperties()
- {
- return TypeDescriptor.GetProperties(this, true);
- }
- public object GetPropertyOwner(PropertyDescriptor pd)
- {
- return this;
- }
- #endregion
- }
- }
|