How to get Resharper to show a Refactoring that it already has.

Posted by AngryHacker on Stack Overflow See other posts from Stack Overflow or by AngryHacker
Published on 2010-01-22T02:02:17Z Indexed on 2010/04/10 3:33 UTC
Read the original article Hit count: 293

Whenever Resharper encounters code like this:

(treeListNode.Tag as GridLine).AdvertiserSeparation = 5;

it presents you with a possible fix (since treeListNode.Tag as GridLine might be null). It says: 'Replace with Direct Cast', which turns the code into the following:

((GridLine) treeListNode.Tag).AdvertiserSeparation = 5;

This is great. However, when it encounters code like this:

GridLine line = treeListNode.Tag as GridLine;
line.AdvertiserSeparation = 5;

Resharper simply displays a warning 'Possible System.NullReferenceException', but does not offer me to 'Replace with Direct Cast'. Is there a way to make Resharper offer me this refactoring, since it already has it?

© Stack Overflow or respective owner

Related posts about resharper

Related posts about visual-studio-2008