This patch fixed the following 2 bugs. Please review and commit
1) The ReflectionPropretyDescriptor must be able to operate with non public properties. 2) The current implementation ignores the fact that the component can be in design mode. In design mode some of the properties (the design-time ones) are supposed to be redirected to the designer. The component which should be used to access the property is retrieved by using MemberDescriptor.GetInvokee (implemented in the patch). Updated the ReflectorPropertyDescriptor to use GetInvokee to decide which component should it use. P.S: Whitespace cleanup in the patch too. Cheers, -- Ivan N. Zlatev Web: http://www.i-nZ.net GPG Key: http://files.i-nZ.net/i-nZ.asc "It's all some kind of whacked out conspiracy."
Index: class/System/System.ComponentModel/MemberDescriptor.cs =================================================================== --- class/System/System.ComponentModel/MemberDescriptor.cs (revision 64506) +++ class/System/System.ComponentModel/MemberDescriptor.cs (working copy) @@ -4,6 +4,7 @@ // Author: // Miguel de Icaza ([EMAIL PROTECTED]) // Andreas Nahr ([EMAIL PROTECTED]) +// Ivan N. Zlatev (contact i-nZ.net) // // (C) Ximian, Inc. http://www.ximian.com // (C) 2003 Andreas Nahr @@ -17,10 +18,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -34,18 +35,19 @@ using System.Collections; using System.Reflection; using System.Runtime.InteropServices; +using System.ComponentModel.Design; namespace System.ComponentModel { [ComVisible (true)] - public abstract class MemberDescriptor + public abstract class MemberDescriptor { private string name; private Attribute [] attrs; private AttributeCollection attrCollection; - + protected MemberDescriptor (string name, Attribute [] attrs) { this.name = name; @@ -69,15 +71,15 @@ attrs = reference.AttributeArray; } - protected virtual Attribute [] AttributeArray + protected virtual Attribute [] AttributeArray { - get + get { - if (attrs == null) + if (attrs == null) { ArrayList list = new ArrayList (); FillAttributes (list); - + ArrayList filtered = new ArrayList (); foreach (Attribute at in list) { bool found = false; @@ -88,11 +90,11 @@ } attrs = (Attribute[]) filtered.ToArray (typeof(Attribute)); } - + return attrs; } - set + set { attrs = value; } @@ -105,7 +107,7 @@ public virtual AttributeCollection Attributes { - get + get { if (attrCollection == null) attrCollection = CreateAttributeCollection (); @@ -117,18 +119,18 @@ { return new AttributeCollection (AttributeArray); } - - public virtual string Category + + public virtual string Category { - get + get { return ((CategoryAttribute) Attributes [typeof (CategoryAttribute)]).Category; } } - public virtual string Description + public virtual string Description { - get + get { foreach (Attribute attr in AttributeArray) { @@ -139,9 +141,9 @@ } } - public virtual bool DesignTimeOnly + public virtual bool DesignTimeOnly { - get + get { foreach (Attribute attr in AttributeArray) { @@ -153,25 +155,25 @@ } } - public virtual string DisplayName + public virtual string DisplayName { - get + get { return name; } } - public virtual string Name + public virtual string Name { - get + get { return name; } } - public virtual bool IsBrowsable + public virtual bool IsBrowsable { - get + get { foreach (Attribute attr in AttributeArray) { @@ -183,15 +185,15 @@ } } - protected virtual int NameHashCode + protected virtual int NameHashCode { - get + get { return name.GetHashCode (); } } - public override int GetHashCode() + public override int GetHashCode() { return base.GetHashCode (); } @@ -200,7 +202,7 @@ { MemberDescriptor other = obj as MemberDescriptor; if (other == null) return false; - + return other.name == name; } @@ -212,24 +214,32 @@ return null; } - [MonoTODO] + // Checks if the component is designed and if it is - returns the designer + // protected static object GetInvokee(Type componentClass, object component) { - // FIXME WHAT should that do??? - - // Lluis: Checked with VS.NET and it always return the component, even if - // it has its own designer set with DesignerAttribute. So, no idea - // what this should do. + if (component is IComponent) { + ISite site = ((IComponent) component).Site; + if (site != null && site.DesignMode) { + IDesignerHost host = site.GetService (typeof (IDesignerHost)) as IDesignerHost; + if (host != null) { + IDesigner designer = host.GetDesigner ((IComponent) component); + if (designer != null && componentClass.IsInstanceOfType (designer)) { + component = designer; + } + } + } + } return component; } - protected static MethodInfo FindMethod(Type componentClass, string name, + protected static MethodInfo FindMethod(Type componentClass, string name, Type[ ] args, Type returnType) { return FindMethod (componentClass, name, args, returnType, true); } - protected static MethodInfo FindMethod(Type componentClass, string name, + protected static MethodInfo FindMethod(Type componentClass, string name, Type[ ] args, Type returnType, bool publicOnly) { BindingFlags bf; Index: class/System/System.ComponentModel/ReflectionPropertyDescriptor.cs =================================================================== --- class/System/System.ComponentModel/ReflectionPropertyDescriptor.cs (revision 64506) +++ class/System/System.ComponentModel/ReflectionPropertyDescriptor.cs (working copy) @@ -3,9 +3,9 @@ // // Author: // Lluis Sanchez Gual ([EMAIL PROTECTED]) +// Ivan N. Zlatev (contact i-nZ.net) +// (C) Novell, Inc. // -// (C) Novell, Inc. -// // // Permission is hereby granted, free of charge, to any person obtaining @@ -15,10 +15,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -40,42 +40,43 @@ { PropertyInfo _member; Type _componentType; - + public ReflectionPropertyDescriptor (Type componentType, PropertyDescriptor oldPropertyDescriptor, Attribute [] attributes) : base (oldPropertyDescriptor, attributes) { _componentType = componentType; } - + public ReflectionPropertyDescriptor (Type componentType, string name, Type type, Attribute [] attributes) : base (name, attributes) { _componentType = componentType; } - + public ReflectionPropertyDescriptor (PropertyInfo info) : base (info.Name, (Attribute[])info.GetCustomAttributes (true)) { _member = info; _componentType = _member.DeclaringType; } - + PropertyInfo GetPropertyInfo () { if (_member == null) { - _member = _componentType.GetProperty (Name); + _member = _componentType.GetProperty (Name, BindingFlags.GetProperty | BindingFlags.NonPublic | + BindingFlags.Public | BindingFlags.Instance); if (_member == null) throw new ArgumentException ("Accessor methods for the " + Name + " property are missing"); } return _member; - } + } - public override Type ComponentType - { + public override Type ComponentType + { get { return _componentType; } } - public override bool IsReadOnly + public override bool IsReadOnly { get { @@ -83,36 +84,37 @@ } } - public override Type PropertyType + public override Type PropertyType { get { return GetPropertyInfo ().PropertyType; } } - + public override object GetValue (object component) { + component = MemberDescriptor.GetInvokee (_componentType, component); return GetPropertyInfo ().GetValue (component, null); } - + DesignerTransaction CreateTransaction (object obj) { IComponent com = obj as IComponent; if (com == null || com.Site == null) return null; - + IDesignerHost dh = (IDesignerHost) com.Site.GetService (typeof(IDesignerHost)); if (dh == null) return null; - + DesignerTransaction tran = dh.CreateTransaction (); IComponentChangeService ccs = (IComponentChangeService) com.Site.GetService (typeof(IComponentChangeService)); if (ccs != null) ccs.OnComponentChanging (com, this); return tran; } - + void EndTransaction (object obj, DesignerTransaction tran, object oldValue, object newValue, bool commit) { if (tran == null) { @@ -120,7 +122,7 @@ OnValueChanged (obj, new PropertyChangedEventArgs (Name)); return; } - + if (commit) { IComponent com = obj as IComponent; IComponentChangeService ccs = (IComponentChangeService) com.Site.GetService (typeof(IComponentChangeService)); @@ -132,14 +134,16 @@ } else tran.Cancel (); } - + public override void SetValue (object component, object value) { DesignerTransaction tran = CreateTransaction (component); - object old = GetValue (component); + object propertyHolder = MemberDescriptor.GetInvokee (_componentType, component); + object old = GetValue (propertyHolder); + try { - GetPropertyInfo ().SetValue (component, value, null); + GetPropertyInfo ().SetValue (propertyHolder, value, null); EndTransaction (component, tran, old, value, true); } catch { EndTransaction (component, tran, old, value, false); @@ -149,26 +153,30 @@ public override void ResetValue (object component) { + object propertyHolder = MemberDescriptor.GetInvokee (_componentType, component); + DefaultValueAttribute attrib = ((DefaultValueAttribute) Attributes[typeof (DefaultValueAttribute)]); - if (attrib != null) - SetValue (component, attrib.Value); - + if (attrib != null) + SetValue (propertyHolder, attrib.Value); + DesignerTransaction tran = CreateTransaction (component); - object old = GetValue (component); - + object old = GetValue (propertyHolder); + try { - MethodInfo mi = component.GetType().GetMethod ("Reset" + Name, Type.EmptyTypes); + MethodInfo mi = propertyHolder.GetType().GetMethod ("Reset" + Name, Type.EmptyTypes); if (mi != null) - mi.Invoke (component, null); - EndTransaction (component, tran, old, GetValue (component), true); + mi.Invoke (propertyHolder, null); + EndTransaction (component, tran, old, GetValue (propertyHolder), true); } catch { - EndTransaction (component, tran, old, GetValue (component), false); + EndTransaction (component, tran, old, GetValue (propertyHolder), false); throw; } } public override bool CanResetValue (object component) { + component = MemberDescriptor.GetInvokee (_componentType, component); + DefaultValueAttribute attrib = ((DefaultValueAttribute) Attributes[typeof (DefaultValueAttribute)]); if (attrib != null) { object current = GetValue (component); @@ -191,6 +199,8 @@ public override bool ShouldSerializeValue (object component) { + component = MemberDescriptor.GetInvokee (_componentType, component); + DefaultValueAttribute attrib = ((DefaultValueAttribute) Attributes[typeof (DefaultValueAttribute)]); if (attrib != null) { object current = GetValue (component);
_______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list