2007-05-08 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / System / System.ComponentModel / TypeConverter.cs
index 1abb70f4182221bb582dd2ddfac7133de4789a94..f0e605098f11c9261465dbafa167e75d029d2df2 100644 (file)
@@ -32,6 +32,7 @@
 
 using System;
 using System.Collections;
+using System.ComponentModel.Design.Serialization;
 using System.Globalization;
 using System.Runtime.InteropServices;
 
@@ -47,6 +48,10 @@ namespace System.ComponentModel
 
                public virtual bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
                {
+                       if (sourceType == typeof (InstanceDescriptor)) {
+                               return true;
+                       }
+
                        return false;
                }
 
@@ -67,6 +72,11 @@ namespace System.ComponentModel
 
                public virtual object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
                {
+                       if (value is InstanceDescriptor) {
+                               return ((InstanceDescriptor) value).Invoke ();
+                       }
+                       if (value == null)
+                               throw new NotSupportedException ("Cannot convert from null");
                        throw new NotSupportedException (this.ToString() + " cannot be created from '" +
                                                         value.GetType().ToString() + "'");
                }
@@ -181,7 +191,7 @@ namespace System.ComponentModel
 
                public PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value)
                {
-                       return GetProperties (context, value, null);
+                       return GetProperties (context, value, new Attribute[1] { BrowsableAttribute.Yes });
                }
 
                public virtual PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context,
@@ -255,11 +265,19 @@ namespace System.ComponentModel
                                this.values = values;
                        }
 
+                       void ICollection.CopyTo (Array array, int index) {
+                               CopyTo (array, index);
+                       }
+
                        public void CopyTo (Array array, int index)
                        {
                                values.CopyTo (array, index);
                        }
 
+                       IEnumerator IEnumerable.GetEnumerator () {
+                               return GetEnumerator ();
+                       }
+
                        public IEnumerator GetEnumerator ()
                        {
                                return values.GetEnumerator ();