[CSHARP-339] Check all implementations of Equals, operator == and GetHashCode Created: 12/Oct/11 Updated: 02/Apr/15 Resolved: 13/Oct/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.2 |
| Fix Version/s: | 1.3 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Robert Stam | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Minor Change | ||||||||
| Description |
|
Some of the implementations of Equals, operator == and GetHashCode are wrong. For example: var x = new BsonInt32(1); Outputs: True 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); Outputs: 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. |
| Comments |
| Comment by Robert Stam [ 13/Oct/11 ] |
|
Only backward breaking if you were relying on Equals coercing between numeric BsonValues (which == still does) or depending on the Equals comparing double.NaN using == instead of the Equals. |