I want to extend the == operator for my object. It is a simple overload, just checking to see if the properties for two objects are all identical:
if(x == null && y == null)
{
return true;
}
return x != null && y != null
&& x.GetType() == y.GetType()
&& x.GetType()
.GetProperties()
.All(property => property.GetValue(x) == property.GetValue(y));
I'm sure most people will see the problem: the == operator is being overridden and thus an infinite recursion occurs on line 1. How can I check to see if x and y are null without recursively calling the == operator?