diff options
author | Lluis Sanchez <lluis@novell.com> | 2004-04-14 18:44:09 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2004-04-14 18:44:09 +0400 |
commit | a0ea05369d94abda5323d5faea39034642a9a861 (patch) | |
tree | c8080ea09db00e9f7a69f4b5a92c749629971874 /mcs/class/System/System.ComponentModel | |
parent | ac0cb3ec24549c62da29609b729d5da60a9124de (diff) |
* AttributeCollection.cs: Added new internal constructor.
* DesignerAttribute.cs: Fixed property TypeId.
* EventDescriptorCollection.cs: Added internal constructor. Added new
method Filter that removes events that do not have the specified
attributes.
* MemberDescriptor.cs: Minor fixes.
* PropertyDescriptor.cs: Implemented some missing methods.
* PropertyDescriptorCollection.cs: Added internal constructor. Implemented
Sort methods.
* ReferenceConverter.cs: Removed some TODOs.
* SyntaxCheck.cs: Implemented CheckMachineName and CheckPath.
* TypeDescriptor.cs: Implemented most of missing methods.
svn path=/trunk/mcs/; revision=25473
Diffstat (limited to 'mcs/class/System/System.ComponentModel')
10 files changed, 493 insertions, 166 deletions
diff --git a/mcs/class/System/System.ComponentModel/AttributeCollection.cs b/mcs/class/System/System.ComponentModel/AttributeCollection.cs index d683ae82655..35e4e1eb1f4 100644 --- a/mcs/class/System/System.ComponentModel/AttributeCollection.cs +++ b/mcs/class/System/System.ComponentModel/AttributeCollection.cs @@ -19,7 +19,12 @@ namespace System.ComponentModel public class AttributeCollection : ICollection, IEnumerable { private ArrayList attrList = new ArrayList (); - public static readonly AttributeCollection Empty = new AttributeCollection (null); + public static readonly AttributeCollection Empty = new AttributeCollection ((ArrayList)null); + + internal AttributeCollection (ArrayList attributes) + { + attrList = attributes; + } public AttributeCollection (Attribute[] attributes) { diff --git a/mcs/class/System/System.ComponentModel/ChangeLog b/mcs/class/System/System.ComponentModel/ChangeLog index f511717893c..26585f13972 100644 --- a/mcs/class/System/System.ComponentModel/ChangeLog +++ b/mcs/class/System/System.ComponentModel/ChangeLog @@ -1,3 +1,18 @@ +2004-04-14 Lluis Sanchez Gual <lluis@ximian.com> + + * AttributeCollection.cs: Added new internal constructor. + * DesignerAttribute.cs: Fixed property TypeId. + * EventDescriptorCollection.cs: Added internal constructor. Added new + method Filter that removes events that do not have the specified + attributes. + * MemberDescriptor.cs: Minor fixes. + * PropertyDescriptor.cs: Implemented some missing methods. + * PropertyDescriptorCollection.cs: Added internal constructor. Implemented + Sort methods. + * ReferenceConverter.cs: Removed some TODOs. + * SyntaxCheck.cs: Implemented CheckMachineName and CheckPath. + * TypeDescriptor.cs: Implemented most of missing methods. + 2004-04-08 Lluis Sanchez Gual <lluis@ximian.com> * AmbientValueAttribute.cs, EnumConverter.cs, ListChangedEventArgs.cs: diff --git a/mcs/class/System/System.ComponentModel/DesignerAttribute.cs b/mcs/class/System/System.ComponentModel/DesignerAttribute.cs index 7eb2b75a84a..1b0a9026a88 100644 --- a/mcs/class/System/System.ComponentModel/DesignerAttribute.cs +++ b/mcs/class/System/System.ComponentModel/DesignerAttribute.cs @@ -65,7 +65,7 @@ namespace System.ComponentModel public override object TypeId { get { - return this.GetType (); + return this.GetType ().ToString() + basetypename.ToString(); } } diff --git a/mcs/class/System/System.ComponentModel/EventDescriptorCollection.cs b/mcs/class/System/System.ComponentModel/EventDescriptorCollection.cs index bd767b0420a..b28a625fadf 100644 --- a/mcs/class/System/System.ComponentModel/EventDescriptorCollection.cs +++ b/mcs/class/System/System.ComponentModel/EventDescriptorCollection.cs @@ -19,12 +19,17 @@ namespace System.ComponentModel { private ArrayList eventList = new ArrayList (); - public static readonly EventDescriptorCollection Empty; + public static readonly EventDescriptorCollection Empty = new EventDescriptorCollection (); private EventDescriptorCollection () { } + internal EventDescriptorCollection (ArrayList list) + { + eventList = list; + } + public EventDescriptorCollection (EventDescriptor[] events) { for (int i = 0; i < events.Length; i++) @@ -128,7 +133,6 @@ namespace System.ComponentModel foreach (object ob in ext) if (ob != null) sorted.Add (ob); - sorted.AddRange (eventList); return sorted; } @@ -139,6 +143,15 @@ namespace System.ComponentModel return col; } + internal EventDescriptorCollection Filter (Attribute[] attributes) + { + EventDescriptorCollection col = new EventDescriptorCollection (); + foreach (EventDescriptor ed in eventList) + if (ed.Attributes.Contains (attributes)) + col.eventList.Add (ed); + return col; + } + public int Count { get { return eventList.Count; diff --git a/mcs/class/System/System.ComponentModel/MemberDescriptor.cs b/mcs/class/System/System.ComponentModel/MemberDescriptor.cs index fffca497811..57bb4212b0a 100755 --- a/mcs/class/System/System.ComponentModel/MemberDescriptor.cs +++ b/mcs/class/System/System.ComponentModel/MemberDescriptor.cs @@ -172,13 +172,13 @@ namespace System.ComponentModel public override int GetHashCode() { - return name.GetHashCode (); + return base.GetHashCode (); } public override bool Equals(object obj) { MemberDescriptor other = obj as MemberDescriptor; - if (obj == null) return false; + if (other == null) return false; return other.name == name; } diff --git a/mcs/class/System/System.ComponentModel/PropertyDescriptor.cs b/mcs/class/System/System.ComponentModel/PropertyDescriptor.cs index eaf2ed0ac4f..82f97187906 100755 --- a/mcs/class/System/System.ComponentModel/PropertyDescriptor.cs +++ b/mcs/class/System/System.ComponentModel/PropertyDescriptor.cs @@ -97,10 +97,25 @@ namespace System.ComponentModel notifiers [component] = handler; } - [MonoTODO] - public virtual void RemoveValueChanged(object component, System.EventHandler handler) + public virtual void RemoveValueChanged (object component, System.EventHandler handler) { - throw new NotImplementedException(); + EventHandler component_notifiers; + + if (component == null) + throw new ArgumentNullException ("component"); + + if (handler == null) + throw new ArgumentNullException ("handler"); + + if (notifiers == null) return; + + component_notifiers = (EventHandler) notifiers [component]; + component_notifiers -= handler; + + if (component_notifiers == null) + notifiers.Remove (component); + else + notifiers [component] = handler; } protected virtual void OnValueChanged (object component, EventArgs e) @@ -131,17 +146,12 @@ namespace System.ComponentModel return Assembly.GetExecutingAssembly ().CreateInstance (type.Name); } - [MonoTODO ("Not correctly implemented")] public override bool Equals(object obj) { - if (!(obj is PropertyDescriptor)) - return false; - if (obj == this) - return true; - return (((PropertyDescriptor) obj).AttributeArray == this.AttributeArray) && - (((PropertyDescriptor) obj).Attributes == this.Attributes) && - (((PropertyDescriptor) obj).DisplayName == this.DisplayName) && - (((PropertyDescriptor) obj).Name == this.Name); + if (!base.Equals (obj)) return false; + PropertyDescriptor other = obj as PropertyDescriptor; + if (other == null) return false; + return other.PropertyType == PropertyType; } public PropertyDescriptorCollection GetChildProperties() @@ -159,22 +169,19 @@ namespace System.ComponentModel return GetChildProperties (null, filter); } - [MonoTODO ("Incorrect implementation")] public override int GetHashCode() { - return Name.GetHashCode (); + return base.GetHashCode (); } - [MonoTODO] - public virtual PropertyDescriptorCollection GetChildProperties(object instance, Attribute[] filter) + public virtual PropertyDescriptorCollection GetChildProperties (object instance, Attribute[] filter) { - throw new NotImplementedException(); + return TypeDescriptor.GetProperties (instance, filter); } - [MonoTODO] public virtual object GetEditor(Type editorBaseType) { - throw new NotImplementedException(); + return TypeDescriptor.GetEditor (PropertyType, editorBaseType); } protected Type GetTypeFromName(string typeName) diff --git a/mcs/class/System/System.ComponentModel/PropertyDescriptorCollection.cs b/mcs/class/System/System.ComponentModel/PropertyDescriptorCollection.cs index 0bc8e330a14..4c0055a3e39 100644 --- a/mcs/class/System/System.ComponentModel/PropertyDescriptorCollection.cs +++ b/mcs/class/System/System.ComponentModel/PropertyDescriptorCollection.cs @@ -19,17 +19,25 @@ namespace System.ComponentModel //[DefaultMember ("Item")] public class PropertyDescriptorCollection : IList, ICollection, IEnumerable, IDictionary { - public static readonly PropertyDescriptorCollection Empty = new PropertyDescriptorCollection (null); + public static readonly PropertyDescriptorCollection Empty = new PropertyDescriptorCollection ((ArrayList)null); ArrayList properties; + internal PropertyDescriptorCollection (ArrayList list) + { + properties = list; + } + public PropertyDescriptorCollection (PropertyDescriptor[] properties) { this.properties = new ArrayList (); if (properties == null) return; - foreach (PropertyDescriptor p in properties) - this.properties.Add (p); + this.properties.AddRange (properties); + } + + private PropertyDescriptorCollection () + { } public int Add (PropertyDescriptor value) @@ -148,42 +156,88 @@ namespace System.ComponentModel RemoveAt (index); } + private PropertyDescriptorCollection CloneCollection () + { + PropertyDescriptorCollection col = new PropertyDescriptorCollection (); + col.properties = (ArrayList) properties.Clone (); + return col; + } + public virtual PropertyDescriptorCollection Sort () { - properties.Sort (); - return this; + PropertyDescriptorCollection col = CloneCollection (); + col.InternalSort ((IComparer) null); + return col; } public virtual PropertyDescriptorCollection Sort (IComparer comparer) { - properties.Sort (comparer); - return this; + PropertyDescriptorCollection col = CloneCollection (); + col.InternalSort (comparer); + return col; } - [MonoTODO] public virtual PropertyDescriptorCollection Sort (string[] order) { - throw new NotImplementedException (); + PropertyDescriptorCollection col = CloneCollection (); + col.InternalSort (order); + return col; } - [MonoTODO] public virtual PropertyDescriptorCollection Sort (string[] order, IComparer comparer) { - throw new NotImplementedException (); + PropertyDescriptorCollection col = CloneCollection (); + ArrayList sorted = col.ExtractItems (order); + col.InternalSort (comparer); + sorted.AddRange (col.properties); + col.properties = sorted; + return col; } - [MonoTODO] protected void InternalSort (IComparer ic) { - throw new NotImplementedException (); + properties.Sort (ic); } - [MonoTODO] protected void InternalSort (string [] order) { - throw new NotImplementedException (); + ArrayList sorted = ExtractItems (order); + InternalSort ((IComparer) null); + sorted.AddRange (properties); + properties = sorted; } - + + ArrayList ExtractItems (string[] names) + { + ArrayList sorted = new ArrayList (properties.Count); + object[] ext = new object [names.Length]; + + for (int n=0; n<properties.Count; n++) + { + PropertyDescriptor ed = (PropertyDescriptor) properties[n]; + int i = Array.IndexOf (names, ed.Name); + if (i != -1) { + ext[i] = ed; + properties.RemoveAt (n); + n--; + } + } + foreach (object ob in ext) + if (ob != null) sorted.Add (ob); + + return sorted; + } + + internal PropertyDescriptorCollection Filter (Attribute[] attributes) + { + ArrayList list = new ArrayList (); + foreach (PropertyDescriptor pd in properties) + if (pd.Attributes.Contains (attributes)) + list.Add (pd); + + return new PropertyDescriptorCollection (list); + } + bool IDictionary.IsFixedSize { get { diff --git a/mcs/class/System/System.ComponentModel/ReferenceConverter.cs b/mcs/class/System/System.ComponentModel/ReferenceConverter.cs index a2e11ee0605..7c4249f1ef9 100644 --- a/mcs/class/System/System.ComponentModel/ReferenceConverter.cs +++ b/mcs/class/System/System.ComponentModel/ReferenceConverter.cs @@ -23,34 +23,27 @@ namespace System.ComponentModel public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType) { - if (sourceType == typeof (string)) - return true; - return base.CanConvertFrom (context, sourceType); + return false; } - [MonoTODO] public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value) { - // Add implementation return base.ConvertFrom(context, culture, value); } - [MonoTODO] public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { - // Add implementation return base.ConvertTo(context, culture, value, destinationType); } - [MonoTODO] public override StandardValuesCollection GetStandardValues (ITypeDescriptorContext context) { - throw new NotImplementedException(); + return null; } public override bool GetStandardValuesExclusive (ITypeDescriptorContext context) diff --git a/mcs/class/System/System.ComponentModel/SyntaxCheck.cs b/mcs/class/System/System.ComponentModel/SyntaxCheck.cs index 287b084a63a..47e12f39e65 100644 --- a/mcs/class/System/System.ComponentModel/SyntaxCheck.cs +++ b/mcs/class/System/System.ComponentModel/SyntaxCheck.cs @@ -18,27 +18,20 @@ namespace System.ComponentModel { } - [MonoTODO ("Don't know what MS wants to do with this")] public static bool CheckMachineName (string value) { if (value == null || value.Trim ().Length == 0) return false; - return Environment.MachineName.Equals (value); + return value.IndexOf ('\\') == -1; } - [MonoTODO ("Don't know what MS wants to do with this")] public static bool CheckPath (string value) { if (value == null || value.Trim ().Length == 0) return false; - try { - Path.GetFullPath (value); - } catch { - return false; - } - return true; + return value.StartsWith (@"\\"); } public static bool CheckRootedPath (string value) diff --git a/mcs/class/System/System.ComponentModel/TypeDescriptor.cs b/mcs/class/System/System.ComponentModel/TypeDescriptor.cs index 05e39de7fdc..45b26f7bb95 100644 --- a/mcs/class/System/System.ComponentModel/TypeDescriptor.cs +++ b/mcs/class/System/System.ComponentModel/TypeDescriptor.cs @@ -23,6 +23,8 @@ public sealed class TypeDescriptor private static readonly string creatingDefaultConverters = "creatingDefaultConverters"; private static Hashtable defaultConverters; private static IComNativeDescriptorHandler descriptorHandler; + private static Hashtable componentTable = new Hashtable (); + private static Hashtable typeTable = new Hashtable (); private TypeDescriptor () { @@ -34,44 +36,49 @@ public sealed class TypeDescriptor throw new NotImplementedException (); } - [MonoTODO] public static IDesigner CreateDesigner(IComponent component, Type designerBaseType) { - throw new NotImplementedException (); + string tn = designerBaseType.AssemblyQualifiedName; + AttributeCollection col = GetAttributes (component); + + foreach (Attribute at in col) { + DesignerAttribute dat = at as DesignerAttribute; + if (dat != null && tn == dat.DesignerBaseTypeName) { + return (IDesigner) Activator.CreateInstance (GetTypeFromName (component, dat.DesignerTypeName)); + } + } + + return null; } - [MonoTODO] public static EventDescriptor CreateEvent (Type componentType, string name, Type type, Attribute [] attributes) { - throw new NotImplementedException (); + return new ReflectionEventDescriptor (componentType, name, type, attributes); } - [MonoTODO] public static EventDescriptor CreateEvent (Type componentType, EventDescriptor oldEventDescriptor, Attribute [] attributes) { - throw new NotImplementedException (); + return new ReflectionEventDescriptor (componentType, oldEventDescriptor, attributes); } - [MonoTODO] public static PropertyDescriptor CreateProperty (Type componentType, string name, Type type, Attribute [] attributes) { - throw new NotImplementedException (); + return new ReflectionPropertyDescriptor (componentType, name, type, attributes); } - [MonoTODO] public static PropertyDescriptor CreateProperty (Type componentType, PropertyDescriptor oldPropertyDescriptor, Attribute [] attributes) { - throw new NotImplementedException (); + return new ReflectionPropertyDescriptor (componentType, oldPropertyDescriptor, attributes); } public static AttributeCollection GetAttributes (Type componentType) @@ -79,8 +86,7 @@ public sealed class TypeDescriptor if (componentType == null) return AttributeCollection.Empty; - object [] atts = componentType.GetCustomAttributes (false); - return new AttributeCollection ((Attribute []) atts); + return GetTypeInfo (componentType).GetAttributes (); } public static AttributeCollection GetAttributes (object component) @@ -88,20 +94,19 @@ public sealed class TypeDescriptor return GetAttributes (component, false); } - [MonoTODO] public static AttributeCollection GetAttributes (object component, bool noCustomTypeDesc) { if (component == null) return AttributeCollection.Empty; - // FIXME: implementation correct? if (noCustomTypeDesc == false && component is ICustomTypeDescriptor) { return ((ICustomTypeDescriptor) component).GetAttributes (); } else { - // FIXME: wrong implementation (we need to check the Attributes of the real instance? - // not of the type? - object [] atts = component.GetType ().GetCustomAttributes (false); - return new AttributeCollection ((Attribute []) atts); + IComponent com = component as IComponent; + if (com != null) + return GetComponentInfo (com).GetAttributes (); + else + return GetTypeInfo (component.GetType()).GetAttributes (); } } @@ -115,7 +120,6 @@ public sealed class TypeDescriptor if (component == null) throw new ArgumentNullException ("component", "component cannot be null"); - // FIXME: implementation correct? if (noCustomTypeDesc == false && component is ICustomTypeDescriptor) { return ((ICustomTypeDescriptor) component).GetClassName (); } else { @@ -133,14 +137,13 @@ public sealed class TypeDescriptor if (component == null) throw new ArgumentNullException ("component", "component cannot be null"); - // FIXME: implementation correct? if (noCustomTypeDesc == false && component is ICustomTypeDescriptor) { return ((ICustomTypeDescriptor) component).GetComponentName (); } else { if (((IComponent) component).Site == null) - return null; + return null; else - return ((IComponent) component).Site.Name; + return ((IComponent) component).Site.Name; } } @@ -149,18 +152,28 @@ public sealed class TypeDescriptor return GetConverter (component.GetType ()); } - [MonoTODO] public static TypeConverter GetConverter (object component, bool noCustomTypeDesc) { if (component == null) throw new ArgumentNullException ("component", "component cannot be null"); - // FIXME: implementation correct? if (noCustomTypeDesc == false && component is ICustomTypeDescriptor) { return ((ICustomTypeDescriptor) component).GetConverter (); } else { - // return the normal converter of this component + AttributeCollection atts = GetAttributes (component, false); + TypeConverterAttribute tca = (TypeConverterAttribute) atts[typeof(TypeConverterAttribute)]; + if (tca != null) { + Type t = GetTypeFromName (component as IComponent, tca.ConverterTypeName); + return (TypeConverter) Activator.CreateInstance (t); + } + + Type type = component.GetType (); + while (type != typeof(object)) + { + TypeConverter con = (TypeConverter) DefaultConverters [type]; + if (con != null) return con; + } return null; } } @@ -211,38 +224,25 @@ public sealed class TypeDescriptor // EnumConverter needs to know the enum type return new EnumConverter(type); } else { - Type t = DefaultConverters [type] as Type; - string converter_name = null; - if (t == null) { - object [] attrs = type.GetCustomAttributes (false); - foreach (object o in attrs){ - if (o is TypeConverterAttribute){ - TypeConverterAttribute tc = (TypeConverterAttribute) o; - converter_name = tc.ConverterTypeName; - break; - } - } - } else { - converter_name = t.FullName; + AttributeCollection atts = GetAttributes (type); + TypeConverterAttribute tca = (TypeConverterAttribute) atts[typeof(TypeConverterAttribute)]; + if (tca != null) { + Type t = GetTypeFromName (null, tca.ConverterTypeName); + return (TypeConverter) Activator.CreateInstance (t); } - - if (converter_name == null) - return null; - - object converter = null; - try { - converter = Activator.CreateInstance (Type.GetType (converter_name)); - } catch (Exception){ + + while (type != typeof(object)) + { + TypeConverter con = (TypeConverter) DefaultConverters [type]; + if (con != null) return con; } - - return converter as TypeConverter; + return null; } } - [MonoTODO] public static EventDescriptor GetDefaultEvent (Type componentType) { - throw new NotImplementedException (); + return GetTypeInfo (componentType).GetDefaultEvent (); } public static EventDescriptor GetDefaultEvent (object component) @@ -250,16 +250,22 @@ public sealed class TypeDescriptor return GetDefaultEvent (component, false); } - [MonoTODO] public static EventDescriptor GetDefaultEvent (object component, bool noCustomTypeDesc) { - throw new NotImplementedException (); + if (!noCustomTypeDesc && (component is ICustomTypeDescriptor)) + return ((ICustomTypeDescriptor) component).GetDefaultEvent (); + else { + IComponent com = component as IComponent; + if (com != null) + return GetComponentInfo (com).GetDefaultEvent (); + else + return GetTypeInfo (component.GetType()).GetDefaultEvent (); + } } - [MonoTODO] public static PropertyDescriptor GetDefaultProperty (Type componentType) { - throw new NotImplementedException (); + return GetTypeInfo (componentType).GetDefaultProperty (); } public static PropertyDescriptor GetDefaultProperty (object component) @@ -267,10 +273,17 @@ public sealed class TypeDescriptor return GetDefaultProperty (component, false); } - [MonoTODO] public static PropertyDescriptor GetDefaultProperty (object component, bool noCustomTypeDesc) { - throw new NotImplementedException (); + if (!noCustomTypeDesc && (component is ICustomTypeDescriptor)) + return ((ICustomTypeDescriptor) component).GetDefaultProperty (); + else { + IComponent com = component as IComponent; + if (com != null) + return GetComponentInfo (com).GetDefaultProperty (); + else + return GetTypeInfo (component.GetType()).GetDefaultProperty (); + } } [MonoTODO] @@ -305,24 +318,27 @@ public sealed class TypeDescriptor return GetEvents (component, attributes, false); } - [MonoTODO] public static EventDescriptorCollection GetEvents (object component, bool noCustomTypeDesc) { - throw new NotImplementedException (); + return GetEvents (component, null, noCustomTypeDesc); } - [MonoTODO] public static EventDescriptorCollection GetEvents (Type componentType, Attribute [] attributes) { - throw new NotImplementedException (); + return GetTypeInfo (componentType).GetEvents (attributes); } - [MonoTODO] - public static EventDescriptorCollection GetEvents (object component, - Attribute [] attributes, - bool noCustomTypeDesc) + public static EventDescriptorCollection GetEvents (object component, Attribute [] attributes, bool noCustomTypeDesc) { - throw new NotImplementedException (); + if (!noCustomTypeDesc && (component is ICustomTypeDescriptor)) + return ((ICustomTypeDescriptor) component).GetEvents (attributes); + else { + IComponent com = component as IComponent; + if (com != null) + return GetComponentInfo (com).GetEvents (attributes); + else + return GetTypeInfo (component.GetType()).GetEvents (attributes); + } } public static PropertyDescriptorCollection GetProperties (object component) @@ -340,50 +356,41 @@ public sealed class TypeDescriptor return GetProperties (component, attributes, false); } - [MonoTODO] public static PropertyDescriptorCollection GetProperties (object component, Attribute [] attributes, bool noCustomTypeDesc) { - Type type = component.GetType (); - if (typeof (ICustomTypeDescriptor).IsAssignableFrom (type)) + if (!noCustomTypeDesc && (component is ICustomTypeDescriptor)) return ((ICustomTypeDescriptor) component).GetProperties (attributes); - - throw new NotImplementedException (); + else { + IComponent com = component as IComponent; + if (com != null) + return GetComponentInfo (com).GetProperties (attributes); + else + return GetTypeInfo (component.GetType()).GetProperties (attributes); + } } - [MonoTODO("noCustomTypeDesc")] public static PropertyDescriptorCollection GetProperties (object component, bool noCustomTypeDesc) { - Type type = component.GetType (); - if (typeof (ICustomTypeDescriptor).IsAssignableFrom (type)) - return ((ICustomTypeDescriptor) component).GetProperties (); - - return GetProperties (type); + return GetProperties (component, null, noCustomTypeDesc); } - [MonoTODO] - public static PropertyDescriptorCollection GetProperties (Type componentType, - Attribute [] attributes) + public static PropertyDescriptorCollection GetProperties (Type componentType, Attribute [] attributes) { - PropertyInfo [] props = componentType.GetProperties (); - DerivedPropertyDescriptor [] propsDescriptor = new DerivedPropertyDescriptor [props.Length]; - int i = 0; - foreach (PropertyInfo prop in props) - { - DerivedPropertyDescriptor propDescriptor = new DerivedPropertyDescriptor (prop.Name, - null, 0); - propDescriptor.SetReadOnly (!prop.CanWrite); - propDescriptor.SetComponentType (componentType); - propDescriptor.SetPropertyType (prop.PropertyType); - propsDescriptor [i++] = propDescriptor; - } - - return new PropertyDescriptorCollection (propsDescriptor); + return GetTypeInfo (componentType).GetProperties (attributes); } - [MonoTODO] - public static void SortDescriptorArray(IList infos) + public static void SortDescriptorArray (IList infos) { - throw new NotImplementedException (); + string[] names = new string [infos.Count]; + object[] values = new object [infos.Count]; + for (int n=0; n<names.Length; n++) { + names[n] = ((MemberDescriptor)infos[n]).Name; + values[n] = infos[n]; + } + Array.Sort (names, values); + infos.Clear(); + foreach (object ob in values) + infos.Add (ob); } public static IComNativeDescriptorHandler ComNativeDescriptorHandler { @@ -391,34 +398,274 @@ public sealed class TypeDescriptor set { descriptorHandler = value; } } - [MonoTODO] public static void Refresh (Assembly assembly) { - throw new NotImplementedException (); + foreach (Type type in assembly.GetTypes()) + Refresh (type); } - [MonoTODO] public static void Refresh (Module module) { - throw new NotImplementedException (); + foreach (Type type in module.GetTypes()) + Refresh (type); } - [MonoTODO] public static void Refresh (object component) { - throw new NotImplementedException (); + lock (componentTable) + { + componentTable.Remove (component); + } + if (Refreshed != null) Refreshed (new RefreshEventArgs (component)); } - [MonoTODO] public static void Refresh (Type type) { - //FIXME this is just to get rid of the warning about Refreshed never being used - if (Refreshed != null) - Refreshed (new RefreshEventArgs (type)); - throw new NotImplementedException (); + lock (typeTable) + { + typeTable.Remove (type); + } + if (Refreshed != null) Refreshed (new RefreshEventArgs (type)); } public static event RefreshEventHandler Refreshed; + + internal static ComponentInfo GetComponentInfo (IComponent com) + { + lock (componentTable) + { + ComponentInfo ci = (ComponentInfo) componentTable [com]; + if (ci == null) { + ci = new ComponentInfo (com); + componentTable [com] = ci; + } + return ci; + } + } + + internal static TypeInfo GetTypeInfo (Type type) + { + lock (typeTable) + { + TypeInfo ci = (TypeInfo) typeTable [type]; + if (ci == null) { + ci = new TypeInfo (type); + typeTable [type] = ci; + } + return ci; + } + } + + static Type GetTypeFromName (IComponent component, string typeName) + { + if (component != null) { + ITypeResolutionService resver = (ITypeResolutionService) component.Site.GetService (typeof(ITypeResolutionService)); + if (resver != null) return resver.GetType (typeName, true, false); + } + + Type t = Type.GetType (typeName); + if (t == null) throw new ArgumentException ("Type '" + typeName + "' not found"); + return t; + } } + + internal abstract class Info + { + Type _infoType; + EventDescriptor _defaultEvent; + bool _gotDefaultEvent; + PropertyDescriptor _defaultProperty; + bool _gotDefaultProperty; + + public Info (Type infoType) + { + _infoType = infoType; + } + + public abstract AttributeCollection GetAttributes (); + public abstract EventDescriptorCollection GetEvents (); + public abstract PropertyDescriptorCollection GetProperties (); + + public Type InfoType + { + get { return _infoType; } + } + + public EventDescriptorCollection GetEvents (Attribute[] attributes) + { + EventDescriptorCollection evs = GetEvents (); + if (attributes == null) return evs; + else return evs.Filter (attributes); + } + + public PropertyDescriptorCollection GetProperties (Attribute[] attributes) + { + PropertyDescriptorCollection props = GetProperties (); + if (attributes == null) return props; + else return props.Filter (attributes); + } + + public EventDescriptor GetDefaultEvent () + { + if (_gotDefaultEvent) return _defaultEvent; + + DefaultEventAttribute attr = (DefaultEventAttribute) GetAttributes()[typeof(DefaultEventAttribute)]; + if (attr == null) + _defaultEvent = null; + else { + EventInfo ei = _infoType.GetEvent (attr.Name); + if (ei == null) + throw new ArgumentException ("Event '" + attr.Name + "' not found in class " + _infoType); + _defaultEvent = new ReflectionEventDescriptor (ei); + } + _gotDefaultEvent = true; + return _defaultEvent; + } + + public PropertyDescriptor GetDefaultProperty () + { + if (_gotDefaultProperty) return _defaultProperty; + + DefaultPropertyAttribute attr = (DefaultPropertyAttribute) GetAttributes()[typeof(DefaultPropertyAttribute)]; + if (attr == null) + _defaultProperty = null; + else { + PropertyInfo ei = _infoType.GetProperty (attr.Name); + if (ei == null) + throw new ArgumentException ("Property '" + attr.Name + "' not found in class " + _infoType); + _defaultProperty = new ReflectionPropertyDescriptor (ei); + } + _gotDefaultProperty = true; + return _defaultProperty; + } + } + + internal class ComponentInfo : Info + { + IComponent _component; + AttributeCollection _attributes; + EventDescriptorCollection _events; + PropertyDescriptorCollection _properties; + + public ComponentInfo (IComponent component): base (component.GetType()) + { + _component = component; + } + + public override AttributeCollection GetAttributes () + { + if (_attributes != null) return _attributes; + + bool cache = true; + object[] ats = _component.GetType().GetCustomAttributes (typeof(DesignerAttribute), true); + Hashtable t = new Hashtable (); + foreach (Attribute at in ats) + t [at.TypeId] = at; + + if (_component.Site != null) + { + ITypeDescriptorFilterService filter = (ITypeDescriptorFilterService) _component.Site.GetService (typeof(ITypeDescriptorFilterService)); + cache = filter.FilterAttributes (_component, t); + } + + ArrayList atts = new ArrayList (); + atts.AddRange (t.Values); + AttributeCollection attCol = new AttributeCollection (atts); + if (cache) _attributes = attCol; + return attCol; + } + + public override EventDescriptorCollection GetEvents () + { + if (_events != null) return _events; + + bool cache = true; + EventInfo[] events = _component.GetType().GetEvents (); + Hashtable t = new Hashtable (); + foreach (EventInfo ev in events) + t [ev.Name] = new ReflectionEventDescriptor (ev); + + if (_component.Site != null) + { + ITypeDescriptorFilterService filter = (ITypeDescriptorFilterService) _component.Site.GetService (typeof(ITypeDescriptorFilterService)); + cache = filter.FilterEvents (_component, t); + } + + ArrayList atts = new ArrayList (); + atts.AddRange (t.Values); + EventDescriptorCollection attCol = new EventDescriptorCollection (atts); + if (cache) _events = attCol; + return attCol; + } + + public override PropertyDescriptorCollection GetProperties () + { + if (_properties != null) return _properties; + + bool cache = true; + PropertyInfo[] props = _component.GetType().GetProperties (); + Hashtable t = new Hashtable (); + foreach (PropertyInfo pr in props) + t [pr.Name] = new ReflectionPropertyDescriptor (pr); + + if (_component.Site != null) + { + ITypeDescriptorFilterService filter = (ITypeDescriptorFilterService) _component.Site.GetService (typeof(ITypeDescriptorFilterService)); + cache = filter.FilterProperties (_component, t); + } + + ArrayList atts = new ArrayList (); + atts.AddRange (t.Values); + PropertyDescriptorCollection attCol = new PropertyDescriptorCollection (atts); + if (cache) _properties = attCol; + return attCol; + } + } + + internal class TypeInfo : Info + { + AttributeCollection _attributes; + EventDescriptorCollection _events; + PropertyDescriptorCollection _properties; + + public TypeInfo (Type t): base (t) + { + } + + public override AttributeCollection GetAttributes () + { + if (_attributes != null) return _attributes; + + object[] atts = InfoType.GetCustomAttributes (true); + _attributes = new AttributeCollection ((Attribute[]) atts); + return _attributes; + } + + public override EventDescriptorCollection GetEvents () + { + if (_events != null) return _events; + + EventInfo[] events = InfoType.GetEvents (); + EventDescriptor[] descs = new EventDescriptor [events.Length]; + for (int n=0; n<events.Length; n++) + descs [n] = new ReflectionEventDescriptor (events[n]); + + _events = new EventDescriptorCollection (descs); + return _events; + } + + public override PropertyDescriptorCollection GetProperties () + { + if (_properties != null) return _properties; + + PropertyInfo[] props = InfoType.GetProperties (); + PropertyDescriptor[] descs = new PropertyDescriptor [props.Length]; + for (int n=0; n<props.Length; n++) + descs [n] = new ReflectionPropertyDescriptor (props[n]); + + _properties = new PropertyDescriptorCollection (descs); + return _properties; + } + } } |