ReferenceEquals and ReSharper Assertion Methods

For those of us that use System.Object.ReferenceEquals when checking for null it can be annoying that ReSharper indicates Possible 'System.NullReferenceException' even though that is precisely what we are doing! There is a solution: add an Assertion Method to ReSharper's Value Analysis Options.

  1. Choose ReSharper > Options
  2. Choose Highlighting > Value Analysis
  3. Under Assertion Methods click Add
  4. Enter: System.Object.ReferenceEquals
  5. Under Assertion Type select != null
  6. Click OK

When you are done you should have something like this:

As the saying goes: Cleanliness is Next to Godliness. Or at least I want my tools reporting the right information.