Quellcode durchsuchen

2008-02-26 Ivan N. Zlatev <[email protected]>

	* Attribute.cs, MonoCustomAttrs: 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.
	* AttributeTest.cs: Remove NotWorking as we pass those tests now.
	* MonoProperty.cs: MS ignores the inherit parameter and defaults to false
	for GetCustomAttributes.
	[Fixes bugs #324472 and #322464]


svn path=/trunk/mcs/; revision=96632
Ivan Zlatev vor 18 Jahren
Ursprung
Commit
8dc53971d0

+ 6 - 0
mcs/class/corlib/System.Reflection/ChangeLog

@@ -1,3 +1,9 @@
+2008-02-26  Ivan N. Zlatev  <[email protected]>
+
+	* MonoProperty.cs: MS ignores the inherit parameter and defaults to false
+	for GetCustomAttributes.
+	[Fixes bugs #324472 and #322464]
+
 2008-02-20  Zoltan Varga  <[email protected]>
 
 	* AssemblyName.cs (ReferenceMatchesDefinition): Add error checking and some 

+ 7 - 4
mcs/class/corlib/System.Reflection/MonoProperty.cs

@@ -193,20 +193,23 @@ namespace System.Reflection {
 			else
 				return null;
 		}
-		
+
+		// According to MSDN the inherit parameter is ignored here and
+		// the behavior always defaults to inherit = false
+		//
 		public override bool IsDefined (Type attributeType, bool inherit)
 		{
-			return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+			return MonoCustomAttrs.IsDefined (this, attributeType, false);
 		}
 
 		public override object[] GetCustomAttributes (bool inherit)
 		{
-			return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+			return MonoCustomAttrs.GetCustomAttributes (this, false);
 		}
 		
 		public override object[] GetCustomAttributes (Type attributeType, bool inherit)
 		{
-			return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+			return MonoCustomAttrs.GetCustomAttributes (this, attributeType, false);
 		}
 
 		public override object GetValue (object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)

+ 22 - 1
mcs/class/corlib/System/Attribute.cs

@@ -224,6 +224,13 @@ namespace System
 			// element parameter is not allowed to be null
 			CheckParameters (element, type);
 
+			// 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);
 		}
 
@@ -248,6 +255,13 @@ namespace System
 			// element parameter is not allowed to be null
 			CheckParameters (element, typeof (Attribute));
 
+			// 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 (inherit);
 		}
 
@@ -301,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);
 		}
 

+ 9 - 0
mcs/class/corlib/System/ChangeLog

@@ -1,3 +1,12 @@
+2008-02-26  Ivan N. Zlatev  <[email protected]>
+
+	* Attribute.cs, MonoCustomAttrs: 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.
+	[Fixes bugs #324472 and #322464]
+
 2008-02-26  Atsushi Enomoto  <[email protected]>
 
 	* DateTime.cs : fix roundtrip regression in Sys.Xml.XmlConvertTests,

+ 26 - 17
mcs/class/corlib/System/MonoCustomAttrs.cs

@@ -305,6 +305,31 @@ namespace System
 		[MethodImplAttribute (MethodImplOptions.InternalCall)]
 		internal static extern bool IsDefinedInternal (ICustomAttributeProvider obj, Type AttributeType);
 
+		static PropertyInfo GetBasePropertyDefinition (PropertyInfo property)
+		{
+			MethodInfo method = property.GetGetMethod (true);
+			if (method == null || !method.IsVirtual)
+				method = property.GetSetMethod (true);
+			if (method == null || !method.IsVirtual)
+				return null;
+
+			MethodInfo baseMethod = method.GetBaseDefinition ();
+			if (baseMethod != null && baseMethod != method) {
+				ParameterInfo[] parameters = property.GetIndexParameters ();
+				if (parameters != null && parameters.Length > 0) {
+					Type[] paramTypes = new Type[parameters.Length];
+					for (int i=0; i < paramTypes.Length; i++)
+						paramTypes[i] = parameters[i].ParameterType;
+					return baseMethod.DeclaringType.GetProperty (property.Name, property.PropertyType, 
+										     paramTypes);
+				} else {
+					return baseMethod.DeclaringType.GetProperty (property.Name, property.PropertyType);
+				}
+			}
+			return null;
+
+		}
+
 		// Handles Type, MonoProperty and MonoMethod.
 		// The runtime has also cases for MonoEvent, MonoField, Assembly and ParameterInfo,
 		// but for those we return null here.
@@ -318,25 +343,9 @@ namespace System
 
 			MethodInfo method = null;
 			if (obj is MonoProperty)
-			{
-				MonoProperty prop = (MonoProperty) obj;
-				method = prop.GetGetMethod (true);
-				if (method == null)
-					method = prop.GetSetMethod (true);
-/*
-				MonoProperty prop = (MonoProperty) obj;
-				if (prop.DeclaringType.BaseType != null) {
-					PropertyInfo baseProp = prop.DeclaringType.BaseType.GetProperty (prop.Name);
-					if (baseProp != prop)
-						return baseProp;
-				}
-				return null;
-*/
-			}
+				return GetBasePropertyDefinition ((MonoProperty) obj);
 			else if (obj is MonoMethod)
-			{
 				method = (MethodInfo) obj;
-			}
 
 			/**
 			 * ParameterInfo -> null

+ 0 - 5
mcs/class/corlib/Test/System/AttributeTest.cs

@@ -129,9 +129,6 @@ namespace MonoTests.System
 		}
 
 		[Test]
-#if NET_2_0
-		[Category ("NotWorking")] // bug #81797
-#endif
 		public void IsDefined_PropertyInfo_Override ()
 		{
 			PropertyInfo pi = typeof (TestSub).GetProperty ("PropBase3");
@@ -218,7 +215,6 @@ namespace MonoTests.System
 		}
 
 		[Test]
-		[Category ("NotWorking")] // bug #81797
 		public void GetCustomAttribute_PropertyInfo_Override ()
 		{
 			PropertyInfo pi = typeof (TestSub).GetProperty ("PropBase3");
@@ -607,7 +603,6 @@ namespace MonoTests.System
 		}
 
 		[Test]
-		[Category ("NotWorking")] // bug #81797
 		public void GetCustomAttributes_PropertyInfo_Override ()
 		{
 			object [] attrs;

+ 4 - 0
mcs/class/corlib/Test/System/ChangeLog

@@ -1,3 +1,7 @@
+2008-02-26  Ivan N. Zlatev  <[email protected]>
+
+	* AttributeTest.cs: Remove NotWorking as we pass those tests now.
+
 2008-02-25  Atsushi Enomoto  <[email protected]>
 
 	* DateTimeTest.cs : enable Bug3522210() and add new test for the bug,