Today I stumbled upon an interesting bug I wrote. I have a set of properties which can be set through a general setter. These properties can be value types or reference type
How about this:
if(object.ReferenceEquals(first, second)) { return; }
if(first.Equals(second)) { return; }
// they must differ, right?
Update
I realized this doesn't work as expected for a certain case:
ReferenceEquals returns false so we fall back to Equals, which behaves as expected.ReferenceEquals returns true, we consider them "same" as expected.ReferenceEquals returns false and Equals returns false, we consider them "different" as expected.ReferenceEquals returns false and Equals returns true, we consider them "same" even though we want "different"So the lesson is "don't get clever"