Author: gert
Date: 2008-02-13 13:53:41 -0500 (Wed, 13 Feb 2008)
New Revision: 95589

Modified:
   branches/mono-1-9/mcs/class/corlib/System/ChangeLog
   branches/mono-1-9/mcs/class/corlib/System/Delegate.cs
Log:
* Delegate.cs (CreateDelegate): Walk the inheritance chain to find
matching method. Fixes bug #360784.


Modified: branches/mono-1-9/mcs/class/corlib/System/ChangeLog
===================================================================
--- branches/mono-1-9/mcs/class/corlib/System/ChangeLog 2008-02-13 18:31:11 UTC 
(rev 95588)
+++ branches/mono-1-9/mcs/class/corlib/System/ChangeLog 2008-02-13 18:53:41 UTC 
(rev 95589)
@@ -1,3 +1,8 @@
+2008-02-12  Gert Driesen  <[EMAIL PROTECTED]>
+
+       * Delegate.cs (CreateDelegate): Walk the inheritance chain to find
+       matching method. Fixes bug #360784.
+
 2008-02-11  Eyal Alaluf <[EMAIL PROTECTED]>
 
        * NumberFormatter.cs: Fix ToString("R") for +-Infinity & NaN.

Modified: branches/mono-1-9/mcs/class/corlib/System/Delegate.cs
===================================================================
--- branches/mono-1-9/mcs/class/corlib/System/Delegate.cs       2008-02-13 
18:31:11 UTC (rev 95588)
+++ branches/mono-1-9/mcs/class/corlib/System/Delegate.cs       2008-02-13 
18:53:41 UTC (rev 95589)
@@ -296,7 +296,8 @@
                        if (!type.IsSubclassOf (typeof (MulticastDelegate)))
                                throw new ArgumentException ("type is not 
subclass of MulticastDelegate.");
 
-                       ParameterInfo[] delargs = type.GetMethod 
("Invoke").GetParameters ();
+                       MethodInfo invoke = type.GetMethod ("Invoke");
+                       ParameterInfo [] delargs = invoke.GetParameters ();
                        Type[] delargtypes = new Type [delargs.Length];
 
                        for (int i=0; i<delargs.Length; i++)
@@ -306,11 +307,29 @@
                         * FIXME: we should check the caller has reflection 
permission
                         * or if it lives in the same assembly...
                         */
-                       BindingFlags flags = BindingFlags.ExactBinding | 
BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic;
+
+                       /*
+                        * since we need to walk the inheritance chain anyway to
+                        * find private methods, adjust the bindingflags to 
ignore
+                        * inherited methods
+                        */
+                       BindingFlags flags = BindingFlags.ExactBinding |
+                               BindingFlags.Public | BindingFlags.Static |
+                               BindingFlags.NonPublic | 
BindingFlags.DeclaredOnly;
                        if (ignoreCase)
                                flags |= BindingFlags.IgnoreCase;
-                       MethodInfo info = target.GetMethod (method, flags, 
null, delargtypes, new ParameterModifier [0]);
 
+                       MethodInfo info = null;
+
+                       for (Type targetType = target; targetType != null; 
targetType = targetType.BaseType) {
+                               MethodInfo mi = targetType.GetMethod (method, 
flags,
+                                       null, delargtypes, new 
ParameterModifier [0]);
+                               if (mi != null) {
+                                       info = mi;
+                                       break;
+                               }
+                       }
+
                        if (info == null) {
                                if (throwOnBindFailure)
                                        throw new ArgumentException ("Couldn't 
bind to method.");
@@ -350,7 +369,8 @@
                        if (!type.IsSubclassOf (typeof (MulticastDelegate)))
                                throw new ArgumentException ("type");
 
-                       ParameterInfo[] delargs = type.GetMethod 
("Invoke").GetParameters ();
+                       MethodInfo invoke = type.GetMethod ("Invoke");
+                       ParameterInfo[] delargs = invoke.GetParameters ();
                        Type[] delargtypes = new Type [delargs.Length];
 
                        for (int i=0; i<delargs.Length; i++)
@@ -360,13 +380,30 @@
                         * FIXME: we should check the caller has reflection 
permission
                         * or if it lives in the same assembly...
                         */
-                       BindingFlags flags = BindingFlags.ExactBinding | 
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
 
+                       /*
+                        * since we need to walk the inheritance chain anyway to
+                        * find private methods, adjust the bindingflags to 
ignore
+                        * inherited methods
+                        */
+                       BindingFlags flags = BindingFlags.ExactBinding | 
+                               BindingFlags.NonPublic | BindingFlags.Public |
+                               BindingFlags.Instance | 
BindingFlags.DeclaredOnly;
+
                        if (ignoreCase)
                                flags |= BindingFlags.IgnoreCase;
 
-                       MethodInfo info = target.GetType ().GetMethod (method, 
flags, null, delargtypes, new ParameterModifier [0]);
+                       MethodInfo info = null;
 
+                       for (Type targetType = target.GetType (); targetType != 
null; targetType = targetType.BaseType) {
+                               MethodInfo mi = targetType.GetMethod (method, 
flags,
+                                       null, delargtypes, new 
ParameterModifier [0]);
+                               if (mi != null) {
+                                       info = mi;
+                                       break;
+                               }
+                       }
+
                        if (info == null)
                                if (throwOnBindFailure)
                                        throw new ArgumentException ("Couldn't 
bind to method '" + method + "'.");

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to