Last active
December 12, 2016 14:00
-
-
Save dgg/f9cd5556cf4684f5f750 to your computer and use it in GitHub Desktop.
equality-implicit-nastysurprises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Money? fiver = 5m.Gbp(); | |
| MonetaryQuantity anotherFiver = (MonetaryQuantity)5m.Gbp(); | |
| Assert.That(EqualityComparer<Money?>.Default.Equals(fiver, anotherFiver), Is.True); | |
| Assert.That(Nullable.Equals(fiver, anotherFiver), Is.True); | |
| Assert.That(fiver.Equals(anotherFiver), Is.True); // fail!!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Money? nullable = new Money(1, “XXX”); | |
| // from Nullable<Money> | |
| MonetaryQuantity succint = nullable; | |
| // from Money thanks to nullable implicit magic | |
| MonetaryQuantity evenMoreSuccint = 1m.Xxx(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment