Resharper is pretty great! We will be buing a couple of licenses. We have once concern though:
We understand using var may increase code readability and manageability in some situations. One example of the former case is when the class names are long, since they won't have to be repeated and it might be easier to read the line without the repitition. One example of the latter is if one class is exchanged for another class, but both classes have an identical method which is the one used. Then code will only have to be changed in one place.
Still, recognizing these advantages we would like it to work this way:
- If var is used when the first token after the = sign is not new, give a warning and suggest replacing var with the returned type of the method called.
- Never suggest using var.
Examples of lines which gives warnings and a refacatoring suggestion to use the returned type of the called method instead:
var a = something.One();
var b = whatever.Boing(1 + 8, "foo");
var c = Werty.SomeMethod();
Examples of lines which do not result in a warning or refactoring suggestion:
Foo foo = something.One();
int b = whatever.Boing(1 + 8, "foo");
Plasebo c = Werty.SomeMethod();
(As standard Resharper seem to always suggest using var, which we do not agree with.)
Is there a way to do exactly what we want?
We will try to use StyleCop as it could be called from our CI-server Hudson. Is the plugin for resharper which uses StyleCop a recommended installation? And does it replace the var functionality above? Should we solve this using StyleCop instead?