// Author:
// Miguel de Icaza (miguel@ximian.com)
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+// Ivan N. Zlatev <contact@i-nz.net>
//
// (C) Ximian, Inc. http://www.ximian.com
// (C) 2003 Andreas Nahr
// 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
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;
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;
}
attrs = (Attribute[]) filtered.ToArray (typeof(Attribute));
}
-
+
return attrs;
}
- set
+ set
{
attrs = value;
}
public virtual AttributeCollection Attributes
{
- get
+ get
{
if (attrCollection == null)
attrCollection = CreateAttributeCollection ();
{
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)
{
}
}
- public virtual bool DesignTimeOnly
+ public virtual bool DesignTimeOnly
{
- get
+ get
{
foreach (Attribute attr in AttributeArray)
{
}
}
- 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)
{
}
}
- protected virtual int NameHashCode
+ protected virtual int NameHashCode
{
- get
+ get
{
return name.GetHashCode ();
}
}
- public override int GetHashCode()
+ public override int GetHashCode()
{
return base.GetHashCode ();
}
{
MemberDescriptor other = obj as MemberDescriptor;
if (other == null) return false;
-
+
return other.name == name;
}
return null;
}
- [MonoTODO]
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.
- return component;
+ 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,
//
// Author:
// Lluis Sanchez Gual (lluis@ximian.com)
-//
-// (C) Novell, Inc.
+// Ivan N. Zlatev (contact i-nZ.net)
+// (C) Novell, Inc.
//
//
// 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
{
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
{
}
}
- 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) {
OnValueChanged (obj, new PropertyChangedEventArgs (Name));
return;
}
-
+
if (commit) {
IComponent com = obj as IComponent;
IComponentChangeService ccs = (IComponentChangeService) com.Site.GetService (typeof(IComponentChangeService));
} 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);
public override void ResetValue (object component)
{
- DefaultValueAttribute attrib = ((DefaultValueAttribute) Attributes[typeof (DefaultValueAttribute)]);
- if (attrib != null)
- SetValue (component, attrib.Value);
+ object propertyHolder = MemberDescriptor.GetInvokee (_componentType, component);
+ DefaultValueAttribute attrib = ((DefaultValueAttribute) Attributes[typeof (DefaultValueAttribute)]);
+ 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);
public override bool ShouldSerializeValue (object component)
{
+ component = MemberDescriptor.GetInvokee (_componentType, component);
+
DefaultValueAttribute attrib = ((DefaultValueAttribute) Attributes[typeof (DefaultValueAttribute)]);
if (attrib != null) {
object current = GetValue (component);