Default NotNull or CanBeNull

In order to improve my static checking of code I would like to require that all methods, properties, and parameters be decorated with either a NotNull or CanBeNull attribute.  Along those lines is there a way to either:

    1. Flag any item that doesn't have one or the other so that I can see them when working with Code Issues.
    2. Have one or other be assumed when neither one is applied. This would make the code cleaner when most items are one or the other as it would remove a lot of [NotNull] lines in the code.  The "Assume entity value can be null:" option gets part way there, but I would like always assume NotNull instead of CanBeNull.
    3. Have a code format option that always adds one or the other when not present, like the option that adds "this" or "var" qualifiers.

I think that for item 1 there may be a way to do it with a custom pattern, but I couldn't quite see how to do it.

Thanks for any ideas!

Comment actions Permalink

The Resharper plugin Agent Johnson supports this.

Check it out at:

Comment actions Permalink

Thanks, I'll give that a try.

Comment actions Permalink

It doesn't do exactly what you want, but it is definitely helpful handling [NotNull] and [CanBeNull].

See also

Perhaps you can post some features suggestions on Agent Johnsons forum.


Please sign in to leave a comment.