Think of the word "Contract" - that you, having written your code, want to guarantee your subscribers (or for Requires , that you want them to guarantee you).
For trivial examples, such as the ones you showed, I cannot think of what you would like to include as a contract. Perhaps for the first, I would go for:
[Pure] public static TimeSpan Seconds(this int i) { Contract.Requires(i>0); Contract.Ensures(Contract.Result<TimeSpan>().TotalSeconds > 0.0); return TimeSpan.FromSeconds(i); }
I guarantee my subscribers that I will get a positive result. Obviously, such a contract could be given if it included more complex mathematics in this method. I will give guarantees on the range, but I will not determine exactly how the result is calculated (since this can be changed).
source share