AngryHacker
AngryHacker

Reputation: 61616

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

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?

Upvotes: 3

Views: 156

Answers (1)

Samuel Neff
Samuel Neff

Reputation: 74909

In the first case, the exception is in the expression and the fix is also in the expression. So the fix is made available. In the second case, the exception is on the assignment line based on a variable, but the fix is in the unrelated expression. Therefore Resharper won't make the fix available here.

The Jetbrains guys are very responsive though, so you can log a case.

http://www.jetbrains.net/jira/browse/RSRP

Upvotes: 1

Related Questions