Is there a way of explicitly specifying that a return value can be null using Code Contracts?
My worry is that methods without a Contract.Ensures(Contract.Result<object>() != null) may be incorrectly ‘fixed’ in the future to include the post-condition, even though the original intention may have been to allow null results.
If there are any other post-conditions then these will indicate that
nullis a valid return value. For example, if a method should return a positive value but usesnullif an error occurs:If you’re worried about regression, though, the best solution might be to add a unit test for an expected
nullreturn value.