Merge pull request #3381 from krytarowski/netbsd-support-20
[mono.git] / mcs / class / corlib / System / Delegate.cs
index ba97e72650908c223b0b84977de1b02726bbd4d7..4064ed9c90185ac0eec46c390977a61b4340a0f9 100644 (file)
@@ -60,6 +60,7 @@ namespace System
                private object m_target;
                private IntPtr method;
                private IntPtr delegate_trampoline;
+               private IntPtr extra_arg;
                private IntPtr method_code;
                private MethodInfo method_info;
 
@@ -101,17 +102,7 @@ namespace System
 
                public MethodInfo Method {
                        get {
-                               if (method_info != null) {
-                                       return method_info;
-                               } else {
-                                       if (method != IntPtr.Zero) {
-                                               if (!method_is_virtual)
-                                                       method_info = (MethodInfo)MethodBase.GetMethodFromHandleNoGenericCheck (new RuntimeMethodHandle (method));
-                                               else
-                                                       method_info = GetVirtualMethod_internal ();
-                                       }
-                                       return method_info;
-                               }
+                               return GetMethodImpl ();
                        }
                }
 
@@ -475,13 +466,15 @@ namespace System
                        return MemberwiseClone ();
                }
 
-               internal bool Compare (Delegate d)
+               public override bool Equals (object obj)
                {
+                       Delegate d = obj as Delegate;
+
                        if (d == null)
                                return false;
-                       
+
                        // Do not compare method_ptr, since it can point to a trampoline
-                       if (d.m_target == m_target && d.method == method) {
+                       if (d.m_target == m_target && d.Method == Method) {
                                if (d.data != null || data != null) {
                                        /* Uncommon case */
                                        if (d.data != null && data != null)
@@ -500,19 +493,25 @@ namespace System
                        return false;
                }
 
-               public override bool Equals (object obj)
-               {
-                       return Compare (obj as Delegate);
-               }
-
                public override int GetHashCode ()
                {
-                       return method.GetHashCode () ^ (m_target != null ? m_target.GetHashCode () : 0);
+                       /* same implementation as CoreCLR */
+                       return GetType ().GetHashCode ();
                }
 
                protected virtual MethodInfo GetMethodImpl ()
                {
-                       return Method;
+                       if (method_info != null) {
+                               return method_info;
+                       } else {
+                               if (method != IntPtr.Zero) {
+                                       if (!method_is_virtual)
+                                               method_info = (MethodInfo)MethodBase.GetMethodFromHandleNoGenericCheck (new RuntimeMethodHandle (method));
+                                       else
+                                               method_info = GetVirtualMethod_internal ();
+                               }
+                               return method_info;
+                       }
                }
 
                // This is from ISerializable
@@ -535,6 +534,12 @@ namespace System
                        if (a == null)
                                return b;
 
+                       if (b == null)
+                               return a;
+
+                       if (a.GetType () != b.GetType ())
+                               throw new ArgumentException (Locale.GetText ("Incompatible Delegate Types. First is {0} second is {1}.", a.GetType ().FullName, b.GetType ().FullName));
+
                        return a.CombineImpl (b);
                }