-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.2
-
Component/s: None
-
None
-
Minor Change
Some of the implementations of Equals, operator == and GetHashCode are wrong.
For example:
var x = new BsonInt32(1);
var y = new BsonDouble(1.0);
Console.WriteLine(x.Equals);
Console.WriteLine(x.GetHashCode());
Console.WriteLine(y.GetHashCode());
Outputs:
True
23866
1072716558
This violates the contract of Equals and GetHashCode, which states that when two objects are Equal, they should have the same hash code.
Another example:
var r = new BsonDouble(double.NaN);
var s = new BsonDouble(double.NaN);
Console.WriteLine(r == s);
Console.WriteLine(r.Equals(s));
Outputs:
False
False
To be consistent with the double data type == should return false and Equals should return true in this case.
There may be other examples, which is why this ticket says to check all implementations.
- is related to
-
CSHARP-338 BsonDouble.Equals fails on NaN
- Closed