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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With