Created
August 7, 2011 19:16
-
-
Save wickedshimmy/1130676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class T : IEquatable<T> { | |
public sealed override int GetHashCode () | |
{ | |
return 4; // guaranteed to be random | |
} | |
public sealed override bool Equals (object o) | |
{ | |
var t = o as T; | |
return t != null && Equals (t); | |
} | |
public bool Equals (T other) | |
{ | |
if (Object.ReferenceEquals (other, null)) | |
return false; | |
if (Object.ReferenceEquals (this, other)) | |
return true; | |
return true; // real equality logic | |
} | |
public static bool operator == (T x, T y) | |
{ | |
if (Object.ReferenceEquals (x, null)) | |
return Object.ReferenceEquals (y, null); | |
return x.Equals (y); | |
} | |
public static bool operator != (T x, T y) | |
{ | |
return !(x == y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment