It is annoying than Contract.Result can not work out its type in some situations. See extract from manual below.
Method Return Values Within postconditions the method’s return value can be referred to via the expression
Contract.Result<T>(), where T is replaced with the return type of the method. When the compiler is unable to infer the type it must be explicitly given. For instance, the C# compiler is unable to infer types for methods that do not take any arguments.
I have noticed that code snippet cen produces Contract.Ensures(Contract.Result<String>() != null); With String highlighted for edit.
Am I missing something, or can I just set the type to Object when comparing to null.
i.e. Contract.Ensures(Contract.Result<Object>() != null);
I would have thought that according to OO theory. That if we have nullable types. Then null conforms to all (nullable) types. Therefore it should work, so I wrote the tests below.
All tests passed.