Fri Jan 3 16:18:27 CET 2003 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Fri, 3 Jan 2003 15:21:29 +0000 (15:21 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Fri, 3 Jan 2003 15:21:29 +0000 (15:21 -0000)
* MonoCustomAttrs.cs: create properly typed arrays when returning
arrays of attributes of a given type.

svn path=/trunk/mcs/; revision=10097

mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/MonoCustomAttrs.cs

index 2db75e35f7b21819d757caef60d0ac67f592bc45..1484eeb4486e1eb35b55b37c70b05c763e55e1bc 100644 (file)
@@ -1,4 +1,9 @@
 
+Fri Jan 3 16:18:27 CET 2003 Paolo Molaro <lupus@ximian.com>
+
+       * MonoCustomAttrs.cs: create properly typed arrays when returning
+       arrays of attributes of a given type.
+
 Fri Jan 3 11:10:14 CET 2003 Paolo Molaro <lupus@ximian.com>
 
        * MonoType.cs: fixed MemberType property for nested types.
index 62a1269272dd7261b0743b1ac4026f16dd9ae664..784a8b24b37b848e553001581344e98bd61a0613 100755 (executable)
@@ -28,10 +28,14 @@ namespace System {
                }
 
                internal static object[] GetCustomAttributes (ICustomAttributeProvider obj, Type attributeType, bool inherit) {
+                       object[] r;
                        object[] res = from_cache (obj);
                        // shortcut
-                       if (res.Length == 1 && (res[0].GetType () == attributeType || res[0].GetType().IsSubclassOf(attributeType)))
-                               return (object[])res.Clone ();
+                       if (res.Length == 1 && (res[0].GetType () == attributeType || res[0].GetType().IsSubclassOf(attributeType))) {
+                               r = (object[])Array.CreateInstance (attributeType, 1);
+                               r [0] = res [0];
+                               return r;
+                       }
                        ArrayList a = new ArrayList ();
                        Type btype = obj as Type;
                        do {
@@ -45,7 +49,7 @@ namespace System {
                                        break;
                                }
                        } while (inherit && btype != null && ((btype = btype.BaseType) != null));
-                       Attribute[] r = new Attribute [a.Count];
+                       r = (object[])Array.CreateInstance (attributeType, a.Count);
                        a.CopyTo (r);
                        return r;
                }