I'm using Microsoft's Code Contracts extension with C#. When I write a class with an overridden ToString implementation that returns null, it correctly identifies the issue:
I assumed this was because Microsoft uses Code Contracts internally, and they added a Contract.Ensures
call to Object.ToString
. However, when I look at the Object.ToString
source code I don't see any contracts (I do see other contracts, but not the one I'm looking for). How does Code Contracts determine that ToString shouldn't return null?