今天我向大家介绍一款个人觉得比较不错的基于.NET的配置文件设计工具:public class MyAssociatedMetadataTypeTypeDescriptionProvider : AssociatedMetadataTypeTypeDescriptionProvider { public MyAssociatedMetadataTypeTypeDescriptionProvider(Type type) : base(type) { } public MyAssociatedMetadataTypeTypeDescriptionProvider(Type type, Type associatedMetadataType) : base(type, associatedMetadataType) { } private ICustomTypeDescriptor Descriptor { get; set; } public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { if (null == this.Descriptor) this.Descriptor = new MyCustomTypeDescriptor(base.GetTypeDescriptor(objectType, instance)); return this.Descriptor; } } public class MyCustomTypeDescriptor : CustomTypeDescriptor { public MyCustomTypeDescriptor(ICustomTypeDescriptor wrappedTypeDescriptor) { this.WrappedTypeDescriptor = wrappedTypeDescriptor; } private ICustomTypeDescriptor WrappedTypeDescriptor { get; set; } public override AttributeCollection GetAttributes() { return this.WrappedTypeDescriptor.GetAttributes(); } public override PropertyDescriptorCollection GetProperties() { PropertyDescriptorCollection properties = this.WrappedTypeDescriptor.GetProperties(); List list = new List(); foreach (PropertyDescriptor descriptor in properties) list.Add(new MyPropertyDescriptor(descriptor)); return new PropertyDescriptorCollection(list.ToArray(), true); } public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { return this.GetProperties(); } } public class MyPropertyDescriptor : PropertyDescriptor { public MyPropertyDescriptor(PropertyDescriptor wrappedPropertyDescriptor) : base(wrappedPropertyDescriptor) { this.WrappedPropertyDescriptor = wrappedPropertyDescriptor; } private PropertyDescriptor WrappedPropertyDescriptor { get; set; } public override void AddValueChanged(object component, EventHandler handler) { this.WrappedPropertyDescriptor.AddValueChanged(component, handler); } public override bool CanResetValue(object component) { return this.WrappedPropertyDescriptor.CanResetValue(component); } public override Type ComponentType { get { return this.WrappedPropertyDescriptor.ComponentType; } } public override bool IsReadOnly { get { return this.WrappedPropertyDescriptor.IsReadOnly; } } public override object GetValue(object component) { return this.WrappedPropertyDescriptor.GetValue(component); } public override Type PropertyType { get { return this.WrappedPropertyDescriptor.PropertyType; } } public override void RemoveValueChanged(object component, EventHandler handler) { this.WrappedPropertyDescriptor.RemoveValueChanged(component, handler); } public override void ResetValue(object component) { this.WrappedPropertyDescriptor.ResetValue(component); } public override void SetValue(object component, object value) { List
然而对于Configuration Section Designer而言,这种繁杂的实现方式已经不复存在。它本身就支持Component Model相关特性的设置,然后会在产生的代码中添加相应的特性描述,大大减轻了开发者的负担。
产生的代码如下:
Configuration Section Designer应该还有很多不错的功能,时间关系我也没有进行深入研究,有兴趣的朋友不妨下载一个Configuration Section Designer体验一下。
最新评论