Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resharper "cleanup code" vs. 'var' keyword

Tags:

c#

resharper

I have an odd behavior with code clean up for c# in visual studio 2008 Team Developer Edition.

Whenever I clean up my code using "Full Cleanup", it replaces all variables declaration with explicit type declarations. But I have set the appropriate settings under "Inspection Severity", "Use var keyword when initializer explicitly declares type" and "use var keyword when possible" to "Show as Error"

Is there any other setting I need to set or is this a known bug?

like image 574
bitbonk Avatar asked Oct 01 '09 13:10

bitbonk


3 Answers

There's a setting under the Code Cleanup section that specifies what Code Cleanup should do with var declarations.

In the ReSharper Menu, select Options. At the bottom of the tree view, select Code Cleanup (in the Tools section). Select a Code Cleanup preset on the right, and then look at the Use 'var' in declaration setting. You probably want the Replace direction setting set to Do not change.

like image 162
bdukes Avatar answered Sep 20 '22 09:09

bdukes


This certainly looks like a bug to me. the var=> type usage works but the type usage => var does not on all of the devs machine here at work (R# 4.5). Posting feedback to R# now.

like image 37
RhysC Avatar answered Sep 20 '22 09:09

RhysC


In Build 5.0.1659.36 there is a bug - "Use 'var' in declaration settings" are not respected.

like image 45
Allan Bush Avatar answered Sep 21 '22 09:09

Allan Bush