Fix handling of null in the non generic implementation of EqualityComparer. Fixes...
authorJb Evain <jbevain@gmail.com>
Wed, 29 Jun 2011 23:24:50 +0000 (01:24 +0200)
committerJb Evain <jbevain@gmail.com>
Wed, 29 Jun 2011 23:24:50 +0000 (01:24 +0200)
mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs

index bb09fa183d4563b60d02b9c48f5193250d2ff7fc..a60f3001b5f93667c78aab1aa92a788e386e78bc 100644 (file)
@@ -45,7 +45,6 @@ namespace System.Collections.Generic {
                                _default = new DefaultComparer ();
                }
                
-               
                public abstract int GetHashCode (T obj);
                public abstract bool Equals (T x, T y);
        
@@ -59,11 +58,23 @@ namespace System.Collections.Generic {
 
                int IEqualityComparer.GetHashCode (object obj)
                {
+                       if (obj == null)
+                               return 0;
+
+                       if (!(obj is T))
+                               throw new ArgumentException ("Argument is not compatible", "obj");
+
                        return GetHashCode ((T)obj);
                }
 
                bool IEqualityComparer.Equals (object x, object y)
                {
+                       if (x == y)
+                               return true;
+
+                       if (x == null || y == null)
+                               return false;
+
                        if (!(x is T))
                                throw new ArgumentException ("Argument is not compatible", "x");
                        if (!(y is T))