2002-12-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / mcs / typemanager.cs
index 4389f2f6d7e5bcb466fc9c71f251356e396b4ab5..f6fda8ca320dbd3b11d7622987e266f067667623 100755 (executable)
@@ -1395,6 +1395,16 @@ public class TypeManager {
 
        public static bool AreMultipleAllowed (Type attr_type)
        {
+               if (!(attr_type is TypeBuilder)) {
+                       System.Attribute [] attrs = System.Attribute.GetCustomAttributes (attr_type);
+
+                       foreach (System.Attribute tmp in attrs)
+                               if (tmp is AttributeUsageAttribute)
+                                       return ((AttributeUsageAttribute) tmp).AllowMultiple;
+
+                       return false;
+               }
+               
                if (attr_to_allowmult == null)
                        return false;
 
@@ -1576,7 +1586,7 @@ public class TypeManager {
 
                        return (MethodInfo) pair.Second;
                } else
-                       return ei.GetAddMethod ();
+                       return ei.GetRemoveMethod ();
        }
 
        static Hashtable priv_fields_events;
@@ -1726,11 +1736,13 @@ public class TypeManager {
 
        // This is a custom version of Convert.ChangeType() which works
        // with the TypeBuilder defined types when compiling corlib.
-       public static object ChangeType (object value, Type conversionType)
+       public static object ChangeType (object value, Type conversionType, out bool error)
        {
-               if (!(value is IConvertible))
-                       throw new ArgumentException ();
-
+               if (!(value is IConvertible)){
+                       error = true;
+                       return null;
+               }
+               
                IConvertible convertValue = (IConvertible) value;
                CultureInfo ci = CultureInfo.CurrentCulture;
                NumberFormatInfo provider = ci.NumberFormat;
@@ -1741,6 +1753,7 @@ public class TypeManager {
                // the system type itself.  You cannot use Type.GetTypeCode()
                // on such a type - it'd always return TypeCode.Object.
                //
+               error = false;
                if (conversionType.Equals (typeof (Boolean)))
                        return (object)(convertValue.ToBoolean (provider));
                else if (conversionType.Equals (typeof (Byte)))
@@ -1774,7 +1787,8 @@ public class TypeManager {
                else if (conversionType.Equals (typeof (Object)))
                        return (object)(value);
                else 
-                       throw new InvalidCastException ();
+                       error = true;
+               return null;
        }
 
        //