Using Reflector or DotPeek, System.Linq.Data.Binary, the implementation of overloading the equality operator is as follows:
[Serializable, DataContract] public sealed class Binary : IEquatable<Binary> { ... public static bool operator ==(Binary binary1, Binary binary2) { return ((binary1 == binary2) || (((binary1 == null) && (binary2 == null)) || (((binary1 != null) && (binary2 != null)) && binary1.EqualsTo(binary2)))); }
Do I need to miss something obvious or is there a mechanism from which I do not know (for example, an implicitly calling object == inside the body?). I admit that I rarely have to overload standard operators.
Why doesn't this implementation lead to infinite recursion (that a simple test shows that it doesn't solve endlessly)? The first conditional expression is binary1 == binary2 in the framework of the operator overload implementation, which will be called if you used binary_1 binary2 outside the implementation, and I would also think inside.
hatchet
source share