ReSharper: Using [NotNull] to generate better code

If you’re a ReSharper user I think this can be very usefull technique in identifying bugs in your code from the very early stage

Christian Harlass's Blog

My all-time-favorite VS plugin, ReSharper, has amongst all the features one which gets hardly noticed: The Annotation Framework and it’s influence on code generation.

The Annotation Framework is a set of “hints” which can be applied to your code, either directly in form of Attributes or stored as an an external XML file (the ReSharper team was using the later method to enhance the .Net Framework libraries). The attributes, which I usually use, are NotNull and CanBeNull. There are some more but those two give you the greatest benefit.

To use them, add at first a reference to theJetBrains.Annotations.dll to your project. It can be found in the ReSharper installation folder (better add a copy to your project and SCM though).Then you can already start annotating your code, such as:

Pretty self-explaing, isn’t it? When trying to assign then null to the person’s name, ReSharper will give…

View original post 86 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: