Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From what I know, it looks like R# has a code inspection to always suggest usage of the var keyword (as you said), but there's no inspection to suggest usage of explicit type when a variable declared using the var keyword is not initialized inline with a new.</p> <p>However, you can achieve that functionality using the R# Code Cleanup functionality. Go to ReSharper | Tools and navigate all the way down in the R# Options dialog. Click "Code Cleanup" under the Tools section. You'll now be showing templates for performing code cleanup including the default template. Now you can either modify it or create a copy of it and modify it as follows (after selecting the template you want to update):</p> <p>Under the C# | Use 'var' in declareation, set the following options (shown in the image attached):</p> <ol> <li>Replace direction:- Can change explicit to 'var' and vice versa</li> <li>Local variable declaration style:- Use 'var' only when initializer has type usage</li> </ol> <p>Now click OK to save the changes.</p> <p>Now you can invoke R# Code Cleanup in an editor window either by Ctrl + E, Ctrl + C (VS Keymap) or via menu ReSharper | Tools | Cleanup Code... In the Code Cleanup dialog, select the template you modified as described and click Run. You'll see that R# will do the following to variable declarations:</p> <ol> <li>Replace var keyword with explicit type where it's not initialized with an explicit new keyword.</li> <li>Replace explicit type with the var keyword where it's initialized with an expilicit new keyword.</li> </ol> <p>The code cleanup options has other numerous options as well that you can set according to your taste.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload