[bcl] Fix Delegate.GetHashCode () so it takes into account the target too. Fixes...
[mono.git] / mcs / class / corlib / System / Delegate.cs
index 6900c420bff44087199bfd5286c1e4d0415c9575..120991b2f79a9de061acadac90235eaa9d4b15fc 100644 (file)
@@ -495,8 +495,11 @@ namespace System
 
                public override int GetHashCode ()
                {
-                       /* same implementation as CoreCLR */
-                       return GetType ().GetHashCode ();
+                       MethodInfo m;
+
+                       m = Method;
+
+                       return (m != null ? m.GetHashCode () : GetType ().GetHashCode ()) ^ (m_target != null ? m_target.GetHashCode () : 0);
                }
 
                protected virtual MethodInfo GetMethodImpl ()
@@ -534,6 +537,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);
                }