I have a method which never returns a null object. I want to make it clear so that users of my API don't have to write code like this:
if(Getxyz() != null)
{
// do stuff
}
How can I show this intent?
I have a method which never returns a null object. I want to make it clear so that users of my API don't have to write code like this:
if(Getxyz() != null)
{
// do stuff
}
How can I show this intent?
Document it and provide the source code.
Either document it well (maybe with .NET standard documentation system) or you have to use some Contract API. Here are some: http://geekswithblogs.net/Podwysocki/archive/2008/01/22/118770.aspx http://www.codeproject.com/KB/cs/designbycontract.aspx
I like to think of it the other way around: if my function could return a null value I better make sure that the function's user knows about it.