Using Reflector or DotPeek, the System.Linq.Data.Binary implementation of the equality operator overload looks like this:
[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))));
}
I must be missing something obvious, or there is a mechanism taking place of which I'm unaware (such as implicitly calling object == within the body?). I admit, I rarely if ever need to overload standard operators.
Why does this implementation not result in an infinite recursion (which a simple test shows it doesn't recurse infinitely)? The first conditional expression is binary1 == binary2, within the implementation of the operator overload that would get called if you used binary1 == binary2 outside the implementation, and I would have thought, inside as well.