Ortiga
Ortiga

Reputation: 8814

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?

Upvotes: 7

Views: 1096

Answers (1)

Ani
Ani

Reputation: 113412

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.

Upvotes: 11

Related Questions