소스 검색

In System:
2008-01-24 Rodrigo Kumpera <[email protected]>

* MonoType.cs (InvokeMember): Check for parameters without default value which
the supplied argument is Missing.Value. Fixes one of the issues of #348522.

In Test/System:
2008-01-24 Rodrigo Kumpera <[email protected]>

* TypeTest.cs (InvokeMember_WithoutDefaultValue): Added test for bug #348522.
It call InvokeMember passing as method argument Missing.Value and a binder that
returns a method that doesn't have a default value for it's parameter.


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

Rodrigo Kumpera 18 년 전
부모
커밋
bd84013322
4개의 변경된 파일76개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      mcs/class/corlib/System/ChangeLog
  2. 4 0
      mcs/class/corlib/System/MonoType.cs
  3. 6 0
      mcs/class/corlib/Test/System/ChangeLog
  4. 61 0
      mcs/class/corlib/Test/System/TypeTest.cs

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

@@ -1,3 +1,8 @@
+2008-01-24  Rodrigo Kumpera  <[email protected]>
+
+	* MonoType.cs (InvokeMember): Check for parameters without default value which
+	the supplied argument is Missing.Value. Fixes one of the issues of #348522.
+
 2008-01-21  Sebastien Pouliot  <[email protected]>
 
 	* DateTimeOffset.cs: Avoid NRE on bad cast if null is provided to

+ 4 - 0
mcs/class/corlib/System/MonoType.cs

@@ -386,6 +386,10 @@ namespace System
 						throwMissingMethodDescription = "Cannot find method " + name + ".";
 				} else {
 					ParameterInfo[] parameters = m.GetParameters();
+					for (int i = 0; i < parameters.Length; ++i) {
+						if (System.Reflection.Missing.Value == args [i] && (parameters [i].Attributes & ParameterAttributes.HasDefault) != ParameterAttributes.HasDefault)
+							throw new ArgumentException (parameters [i].Name);
+					}
 					bool hasParamArray = parameters.Length > 0 ? Attribute.IsDefined (parameters [parameters.Length - 1], 
 						typeof (ParamArrayAttribute)) : false;
 					if (hasParamArray)

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

@@ -1,3 +1,9 @@
+2008-01-24  Rodrigo Kumpera  <[email protected]>
+
+	* TypeTest.cs (InvokeMember_WithoutDefaultValue): Added test for bug #348522.
+	It call InvokeMember passing as method argument Missing.Value and a binder that
+	returns a method that doesn't have a default value for it's parameter.
+
 2008-01-21  Gert Driesen  <[email protected]>
 
         * AppDomainTest.cs: Added DefineDynamicAssembly tests for invalid

+ 61 - 0
mcs/class/corlib/Test/System/TypeTest.cs

@@ -180,6 +180,49 @@ namespace MonoTests.System
 	{
 	}
 #endif
+	public class Bug348522
+	{
+		public void Test (int __argument)
+		{
+		}
+	}
+
+	public class FirstMethodBinder : Binder
+	{
+		public override MethodBase BindToMethod (BindingFlags bindingAttr, MethodBase [] match, ref object [] args,
+							 ParameterModifier [] modifiers, CultureInfo culture, string [] names,
+							 out object state)
+		{
+			state = null;
+			return match [0];
+		}
+		
+		public override object ChangeType (object value, Type type1, CultureInfo culture)
+		{
+			return value;
+		}
+		
+		// The rest is just to please the compiler
+		public override FieldInfo BindToField (BindingFlags a, FieldInfo[] b, object c, CultureInfo d)
+		{
+			return null;
+		}
+		
+		public override void ReorderArgumentArray(ref object[] a, object b)
+		{
+		}
+		
+		public override MethodBase SelectMethod(BindingFlags a, MethodBase[] b, Type[] c, ParameterModifier[] d)
+		{
+		    return null;
+		}
+		
+		public override PropertyInfo SelectProperty(BindingFlags a, PropertyInfo[] b, Type c, Type[] d, ParameterModifier[] e)
+		{
+			return null;
+		}
+	}
+
 
 	[TestFixture]
 	public class TypeTest
@@ -2044,6 +2087,24 @@ PublicKeyToken=b77a5c561934e089"));
 			Assert.AreEqual ("#A:1|2,3,4", result, "#B2");
 		}
 
+	
+		[Test] // bug #348522
+		public void InvokeMember_WithoutDefaultValue ()
+		{
+			BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod;;
+			try {
+				typeof (Bug348522).InvokeMember ("Test", flags, new FirstMethodBinder (), new Bug348522(),
+					new object [] {Missing.Value}, null, null, null);
+				Assert.Fail ("#1");
+			} catch (ArgumentException ex) {
+				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("__argument", ex.ParamName, "#6");
+			}
+		}
+
 		class X
 		{
 			public static int Value;