[Mono-list] System.Delegate bugs and fix

Nick nick@chemlab.org
27 Aug 2002 20:13:22 -0400


--=-Bp7YxFH6UYs975vxwpTs
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Ah, sorry about that. Erroneous cut 'n paste.

Nick

On Tue, 2002-08-27 at 11:38, Paolo Molaro wrote:

> On 08/27/02 Paolo Molaro wrote:
> > +                       BindingFlags flags = BindingFlags.Public | BindingFlags.Static;
> > 
> > Why doesn't this include BindingFlags.Public?
> 
> BindingFlags.Instance is what I meant:-/
> 
> lupus
> 
> -- 
> -----------------------------------------------------------------
> lupus@debian.org                                     debian/rules
> lupus@ximian.com                             Monkeys do it better
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list


--=-Bp7YxFH6UYs975vxwpTs
Content-Disposition: attachment; filename=delegate.cs.diff
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=delegate.cs.diff; charset=ISO-8859-1

Common subdirectories: mcs/class/corlib/System/CVS and mcs.niko/class/corli=
b/System/CVS
diff -u mcs/class/corlib/System/ChangeLog mcs.niko/class/corlib/System/Chan=
geLog
--- 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 -0=
400
@@ -1,3 +1,11 @@
+2002-08-27  Nick Zigarovich <nick@chemlab.org>
+
+	* 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 <gonzalo@ximian.com>
=20
 	* Double.cs: implemented TryParse.
=20
diff -u mcs/class/corlib/System/Delegate.cs mcs.niko/class/corlib/System/De=
legate.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 @@
=20
 			return CreateDelegate_internal (type, null, info);
 		}
-	=09
+
 		public static Delegate CreateDelegate (Type type, object target, string =
method)
 		{
-			if (type =3D=3D null)
-				throw new ArgumentNullException (Locale.GetText ("Type is null"));
-
-			if (target =3D=3D null)
-				throw new ArgumentNullException (Locale.GetText ("Target object is nul=
l"));
-
-			if (method =3D=3D null)
-				throw new ArgumentNullException (Locale.GetText ("method string is nul=
l"));
-
-			BindingFlags flags =3D  BindingFlags.Public | BindingFlags.Instance;
-			MethodInfo info =3D target.GetType ().GetMethod (method, flags);
-			return CreateDelegate_internal (type, target, info);
+			return CreateDelegate(type, target, method, false);
 		}
=20
  		public static Delegate CreateDelegate (Type type, Type target, string m=
ethod)
@@ -112,8 +101,18 @@
 			if (method =3D=3D null)
 				throw new ArgumentNullException (Locale.GetText ("method string is nul=
l"));
=20
+			ParameterInfo[] delargs =3D type.GetMethod ("Invoke").GetParameters ();
+			Type[] delargtypes =3D new Type [delargs.Length];
+
+			for (int i=3D0; i<delargs.Length; i++)
+				delargtypes [i] =3D delargs [i].ParameterType;
+
 			BindingFlags flags =3D  BindingFlags.Public | BindingFlags.Static;
-			MethodInfo info =3D target.GetMethod (method, flags);
+			MethodInfo info =3D target.GetMethod (method, flags, null, delargtypes,=
 new ParameterModifier [0]);
+
+			if (info =3D=3D null)
+				throw new ArgumentException ("Couldn't bind to method");
+
 			return CreateDelegate_internal (type, null, info);
 		}
=20
@@ -127,11 +126,24 @@
=20
 			if (method =3D=3D null)
 				throw new ArgumentNullException (Locale.GetText ("method string is nul=
l"));
-		=09
-			Type target_type =3D target.GetType ();
-			BindingFlags flags =3D  BindingFlags.Public | BindingFlags.Instance | B=
indingFlags.IgnoreCase;
-			MethodInfo info =3D target_type.GetMethod (method, flags);
-			return CreateDelegate_internal (type, target, info);		=09
+
+			ParameterInfo[] delargs =3D type.GetMethod ("Invoke").GetParameters ();
+			Type[] delargtypes =3D new Type [delargs.Length];
+
+			for (int i=3D0; i<delargs.Length; i++)
+				delargtypes [i] =3D delargs [i].ParameterType;
+
+			BindingFlags flags =3D BindingFlags.Public | BindingFlags.Instance;
+
+			if (ignorecase)
+				flags |=3D BindingFlags.IgnoreCase;
+
+			MethodInfo info =3D target.GetType ().GetMethod (method, flags, null, d=
elargtypes, new ParameterModifier [0]);
+
+			if (info =3D=3D null)
+				throw new ArgumentException ("Couldn't bind to method");
+
+			return CreateDelegate_internal (type, target, info);
 		}
=20
 		public object DynamicInvoke( object[] args )
Common subdirectories: mcs/class/corlib/System/Text and mcs.niko/class/corl=
ib/System/Text

--=-Bp7YxFH6UYs975vxwpTs--