We are implementing some web services, and need to ensure that some of our methods always return non-null values.
We've investigated two ways of doing this:
- Using code contracts, and returning the default value using
Ensures
constraints on the return value. - Using an aspect-oriented programming approach using PostSharp.
Both approaches work, but I'm wondering whether there are any other approaches that we should consider.
How would you enforce non-null return values?
Looks like there was a similar question on SO, and Jon Skeet recommends the Code Contract approach.