Rebuild custom var template

Code Verification Resharper suggests using var in C # instead of an explicit type almost everywhere. I do not like this parameter because too many var makes things unclear, so I turned off this option. However, when I like to use var, in cases of initialization twice the type on the same line with generics (so in similar situations, like the diamond operator from java 7), for example:

Dictionary<string string> dic = new Dictionary<string, string>(); // I want a suggestion to replace this to var dic = new Dictionary<string, string>(); // but I don't want to replace things like this: Person p = new Person(); 

I made my own template in Resharper:

 Dictionary<$type1$, $type2$> $id$ = new Dictionary<$type1$, $type2$>(); 

with replacement by:

 var $id$ = new Dictionary<$type1$, $type2$>(); 

This works fine, but the pattern also finds strings that have already been converted with the rule. Why and how to fix it?

Edit: put part of the text in bold because no one is reading it.

+7
c # visual-studio resharper var
source share
2 answers

Resharper has 2 code checks for the 'var' keyword. Go to Resharper Options... Code Inspection Inspection Severity and change the keyword 'Use' var 'if possible' to a lesser extent. (Note that on the Severity Screen, you can search for words in the text box at the top)

enter image description here

+1
source share
  • Resharper Menu
  • "Options"
  • "Code Verification", then "Verification Level", search for "Use the keyword" If possible "and set to" Do not show "
-3
source share

All Articles