using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using System.Xml; using System.Xml.Serialization; using System.Xml.Schema; namespace VEPROMS.CSLA.Library { public class DynamicPropertyDescriptor : PropertyDescriptor { private PropertyDescriptor _BasePropertyDescriptor; private ConfigDynamicTypeDescriptor _Instance; public DynamicPropertyDescriptor(ConfigDynamicTypeDescriptor instance, PropertyDescriptor basePropertyDescriptor) : base(basePropertyDescriptor) { _Instance = instance; _BasePropertyDescriptor = basePropertyDescriptor; } public override bool CanResetValue(object component) { return _BasePropertyDescriptor.CanResetValue(component); } public override Type ComponentType { get { return _BasePropertyDescriptor.ComponentType; } } public override object GetValue(object component) { return _BasePropertyDescriptor.GetValue(component); } public override bool IsReadOnly { get { return _Instance.IsReadOnly; } } public override Type PropertyType { get { return _BasePropertyDescriptor.PropertyType; } } public override void ResetValue(object component) { _BasePropertyDescriptor.ResetValue(component); } public override bool ShouldSerializeValue(object component) { return _BasePropertyDescriptor.ShouldSerializeValue(component); } public override void SetValue(object component, object value) { _BasePropertyDescriptor.SetValue(component, value); } } [Serializable()] public class ConfigDynamicTypeDescriptor //: ICustomTypeDescriptor//, ISupportInitialize { #region Events public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(String info) { _IsDirty = true; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(info)); } [NonSerialized] private bool _IsDirty = false; [XmlIgnore] [Browsable(false)] public bool IsDirty { get { return _IsDirty; } set { _IsDirty = value; } } #endregion [NonSerialized] private PropertyDescriptorCollection dynamicProps; private bool _IsReadOnly = false; internal virtual bool IsReadOnly { get { return _IsReadOnly; } set { _IsReadOnly = value; } } public ConfigDynamicTypeDescriptor() { } #region "TypeDescriptor Implementation" public String GetClassName() { return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() { return TypeDescriptor.GetAttributes(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) { return GetProperties(); } public PropertyDescriptorCollection GetProperties() { if (dynamicProps == null) { PropertyDescriptorCollection baseProps = TypeDescriptor.GetProperties(this, true); dynamicProps = new PropertyDescriptorCollection(null); foreach (PropertyDescriptor oProp in baseProps) { dynamicProps.Add(new DynamicPropertyDescriptor(this, oProp)); } } return dynamicProps; } public object GetPropertyOwner(PropertyDescriptor pd) { return this; } #endregion } }