+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.
}
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 {
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;
}