Hiya folks,

System.Delegate::CreateDelegate methods that take a method name as a
string argument were using System.Type::GetMethod(string, BindingFlags)
for method lookups, resulting in incorrect behavior when looking up
overloaded methods.

System.Delegate::CreateDelegate (Type,object,string,bool) was ignoring
the bool flag.

diff attached...

niko

Common subdirectories: mcs/class/corlib/System/CVS and mcs.niko/class/corlib/System/CVS
diff -u mcs/class/corlib/System/ChangeLog mcs.niko/class/corlib/System/ChangeLog
--- mcs/class/corlib/System/ChangeLog	2002-08-27 03:48:12.000000000 -0400
+++ mcs.niko/class/corlib/System/ChangeLog	2002-08-27 03:40:48.000000000 -0400
@@ -1,3 +1,11 @@
+2002-08-27  Nick Zigarovich <[EMAIL PROTECTED]>
+
+	* Delegate.cs:
+	  - CreateDelegate (Type,object,string,bool) always used
+	    BindingFlags.IgnoreCase regardless of the Bool param.
+	  - Some CreateDelegate methods were were looking up target
+	    methods by name only, no parameter matching.
+
 2002-08-23  Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
 	* Double.cs: implemented TryParse.
 
diff -u mcs/class/corlib/System/Delegate.cs mcs.niko/class/corlib/System/Delegate.cs
--- mcs/class/corlib/System/Delegate.cs	2002-08-27 03:48:12.000000000 -0400
+++ mcs.niko/class/corlib/System/Delegate.cs	2002-08-27 03:39:22.000000000 -0400
@@ -84,21 +84,10 @@
 
 			return CreateDelegate_internal (type, null, info);
 		}
-		
+
 		public static Delegate CreateDelegate (Type type, object target, string method)
 		{
-			if (type == null)
-				throw new ArgumentNullException (Locale.GetText ("Type is null"));
-
-			if (target == null)
-				throw new ArgumentNullException (Locale.GetText ("Target object is null"));
-
-			if (method == null)
-				throw new ArgumentNullException (Locale.GetText ("method string is null"));
-
-			BindingFlags flags =  BindingFlags.Public | BindingFlags.Instance;
-			MethodInfo info = target.GetType ().GetMethod (method, flags);
-			return CreateDelegate_internal (type, target, info);
+			return CreateDelegate(type, target, method, false);
 		}
 
  		public static Delegate CreateDelegate (Type type, Type target, string method)
@@ -112,8 +101,18 @@
 			if (method == null)
 				throw new ArgumentNullException (Locale.GetText ("method string is null"));
 
+			ParameterInfo[] delargs = type.GetMethod ("Invoke").GetParameters ();
+			Type[] delargtypes = new Type [delargs.Length];
+
+			for (int i=0; i<delargs.Length; i++)
+				delargtypes [i] = delargs [i].ParameterType;
+
 			BindingFlags flags =  BindingFlags.Public | BindingFlags.Static;
-			MethodInfo info = target.GetMethod (method, flags);
+			MethodInfo info = target.GetMethod (method, flags, null, delargtypes, new ParameterModifier [0]);
+
+			if (info == null)
+				throw new ArgumentException ("Couldn't bind to method");
+
 			return CreateDelegate_internal (type, null, info);
 		}
 
@@ -127,11 +126,24 @@
 
 			if (method == null)
 				throw new ArgumentNullException (Locale.GetText ("method string is null"));
-			
-			Type target_type = target.GetType ();
-			BindingFlags flags =  BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase;
-			MethodInfo info = target_type.GetMethod (method, flags);
-			return CreateDelegate_internal (type, target, info);			
+
+			ParameterInfo[] delargs = type.GetMethod ("Invoke").GetParameters ();
+			Type[] delargtypes = new Type [delargs.Length];
+
+			for (int i=0; i<delargs.Length; i++)
+				delargtypes [i] = delargs [i].ParameterType;
+
+			BindingFlags flags = BindingFlags.Public | BindingFlags.Static;
+
+			if (ignorecase)
+				flags |= BindingFlags.IgnoreCase;
+
+			MethodInfo info = target.GetType ().GetMethod (method, flags, null, delargtypes, new ParameterModifier [0]);
+
+			if (info == null)
+				throw new ArgumentException ("Couldn't bind to method");
+
+			return CreateDelegate_internal (type, target, info);
 		}
 
 		public object DynamicInvoke( object[] args )
Common subdirectories: mcs/class/corlib/System/Text and mcs.niko/class/corlib/System/Text

Reply via email to