1 // System.MonoCustomAttrs.cs
2 // Hooks into the runtime to get custom attributes for reflection handles
4 // Paolo Molaro (lupus@ximian.com)
6 // (c) 2002 Ximian, Inc.
9 using System.Reflection;
10 using System.Collections;
11 using System.Runtime.CompilerServices;
14 internal class MonoCustomAttrs {
16 static Hashtable handle_to_attrs = new Hashtable ();
18 [MethodImplAttribute(MethodImplOptions.InternalCall)]
19 internal static extern object[] GetCustomAttributes (ICustomAttributeProvider obj);
21 private static object[] from_cache (ICustomAttributeProvider obj) {
22 object[] res = (object[])handle_to_attrs [obj];
25 res = GetCustomAttributes (obj);
26 handle_to_attrs.Add (obj, res);
30 internal static object[] GetCustomAttributes (ICustomAttributeProvider obj, Type attributeType, bool inherit) {
32 object[] res = from_cache (obj);
34 if (res.Length == 1 && res[0].GetType () == attributeType)
36 ArrayList a = new ArrayList ();
37 foreach (object attr in res) {
38 if (attributeType.Equals (attr.GetType ()))
44 internal static object[] GetCustomAttributes (ICustomAttributeProvider obj, bool inherit) {
46 return from_cache (obj);
48 internal static bool IsDefined (ICustomAttributeProvider obj, Type attributeType, bool inherit) {
50 object[] res = from_cache (obj);
51 foreach (object attr in res) {
52 if (attributeType.Equals (attr.GetType ()))