Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2008 - Replace var with inferred type

My team just received the code written by a contractor, and the contractor had a preference for using type inference with var. Our team prefers explicit typing by using the actual type (as in below):

Type someName = new Type();
IList<TypeTwo> someOther = someClass.getStuff();

Whereas the contractor delivered

var someOther = someClass.getStuff();

Visual Studio 2008 knows what the inferred type is, as I can see by hovering the var keyword

My question is, is there a way to do a global find and replace var to the inferred type?

like image 295
Ortiga Avatar asked Dec 06 '11 16:12

Ortiga


1 Answers

I don't think VS 2008 (or 2010 for that matter) has this functionality, but ReSharper has the "Replace 'var' with explicit type declaration" context-action that you can use on a case-by-case basis to type locals explicitly. If you want to go the whole hog, there's a "Code Cleanup" operation that can be used to perform this refactoring for an entire block/file/project/solution.

Do note that this plugin is not free.

like image 185
Ani Avatar answered Sep 21 '22 03:09

Ani