2009-07-14 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mcs / class / corlib / System / Attribute.cs
index 1e92fa4b31cffe482725ffe1c6dce21bc0fff43a..6739580aec7066f289f7e304b855f08ef2a47540 100644 (file)
@@ -39,6 +39,7 @@ namespace System
 
 #if NET_2_0
        [ComVisible (true)]
+       [ComDefaultInterface (typeof (_Attribute))]
 #endif
 
 #if NET_1_1
@@ -189,9 +190,9 @@ namespace System
                        return GetCustomAttributes (element, attributeType, true);
                }
 
-               public static Attribute[] GetCustomAttributes (MemberInfo element, Type attributeType)
+               public static Attribute[] GetCustomAttributes (MemberInfo element, Type type)
                {
-                       return GetCustomAttributes (element, attributeType, true);
+                       return GetCustomAttributes (element, type, true);
                }
 
                public static Attribute[] GetCustomAttributes (Assembly element, Type attributeType, bool inherit)
@@ -218,12 +219,19 @@ namespace System
                        return (Attribute []) element.GetCustomAttributes (attributeType, inherit);
                }
 
-               public static Attribute[] GetCustomAttributes (MemberInfo element, Type attributeType, bool inherit)
+               public static Attribute[] GetCustomAttributes (MemberInfo element, Type type, bool inherit)
                {
                        // element parameter is not allowed to be null
-                       CheckParameters (element, attributeType);
+                       CheckParameters (element, type);
 
-                       return (Attribute []) element.GetCustomAttributes (attributeType, inherit);
+                       // MS ignores the inherit param in PropertyInfo's ICustomAttributeProvider 
+                       // implementation, but not in the Attributes, so directly get the attributes
+                       // from MonoCustomAttrs instead of going throught the PropertyInfo's 
+                       // ICustomAttributeProvider
+                       MemberTypes mtype = element.MemberType;
+                       if (mtype == MemberTypes.Property)
+                               return (Attribute []) MonoCustomAttrs.GetCustomAttributes (element, type, inherit);
+                       return (Attribute []) element.GetCustomAttributes (type, inherit);
                }
 
                public static Attribute[] GetCustomAttributes (Module element, bool inherit)
@@ -247,7 +255,14 @@ namespace System
                        // element parameter is not allowed to be null
                        CheckParameters (element, typeof (Attribute));
 
-                       return (Attribute []) element.GetCustomAttributes (inherit);
+                       // MS ignores the inherit param in PropertyInfo's ICustomAttributeProvider 
+                       // implementation, but not in the Attributes, so directly get the attributes
+                       // from MonoCustomAttrs instead of going throught the PropertyInfo's 
+                       // ICustomAttributeProvider
+                       MemberTypes mtype = element.MemberType;
+                       if (mtype == MemberTypes.Property)
+                               return (Attribute []) MonoCustomAttrs.GetCustomAttributes (element, inherit);
+                       return (Attribute []) element.GetCustomAttributes (typeof (Attribute), inherit);
                }
 
                public static Attribute[] GetCustomAttributes (ParameterInfo element, bool inherit)
@@ -300,7 +315,14 @@ namespace System
                                mtype != MemberTypes.NestedType)
                                throw new NotSupportedException (Locale.GetText (
                                        "Element is not a constructor, method, property, event, type or field."));
-
+#if NET_2_0
+                       // MS ignores the inherit param in PropertyInfo's ICustomAttributeProvider 
+                       // implementation, but not in the Attributes, so directly get the attributes
+                       // from MonoCustomAttrs instead of going throught the PropertyInfo's 
+                       // ICustomAttributeProvider
+                       if (mtype == MemberTypes.Property)
+                               return MonoCustomAttrs.IsDefined (element, attributeType, inherit);
+#endif
                        return ((MemberInfo) element).IsDefined (attributeType, inherit);
                }