How can I show that a method will never return null (Design by contract) in C# -


I have a method that never gives empty objects, I want to make it clear so that users of my API Type the code like this:

  if (getxyz ()! = Null) {// do stuff}  

How can I show this intention?

Creating Cause Without Cause

You document this fact But it will not be checked automatically.

If you are using a recharge, then the method can be set to check it properly, the method is marked with a [notion] attribute.

Otherwise you can use the library and you can add something according to your method, but for such simple explanation, this is a lot more extraordinary. / P>

  contract.insons (contract. Sage  (=!) = Null)  

Tip # solved this problem with permission is! After the type to mark it as a non-null type, such as

  string! Foo  

but use only Tip # to Can be used to target NET2, and has been used by Code Contracts Library.


Comments