I want to let programmers and myself know that a method does not want null
and if you do send null
to it anyways, the result will not be pretty. >
This can be done either with AOP, whereby an Advice verifies at run-time whether a method parameter is null and whether nulls are allowed. See PostSharp and Spring.NET for AOP.
As for ReSharper, see Annotated Framework:
We have analyzed a great share of .NET Framework Class Library, as well as NUnit Framework, and annotated it through external XML files, using a set of custom attributes from the JetBrains.Annotations namespace, specifically:
- StringFormatMethodAttribute (for methods that take format strings as parameters)
- InvokerParameterNameAttribute (for methods with string literal arguments that should match one of caller parameters)
- AssertionMethodAttribute (for assertion methods)
- AssertionConditionAttribute (for condition parameters of assertion methods)
- TerminatesProgramAttribute (for methods that terminate control flow)
- CanBeNullAttribute (for values that can be null)
- NotNullAttribute (for values that can not be null)