VS2008 - 用推断类型替换 var [英] VS2008 - Replace var with inferred type

查看:21
本文介绍了VS2008 - 用推断类型替换 var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队刚刚收到了一个承包商编写的代码,承包商偏爱使用带有 var 的类型推断.我们的团队更喜欢使用实际类型(如下所示)进行显式输入:

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();

而承包商交付

var someOther = someClass.getStuff();

Visual Studio 2008 知道推断的类型是什么,我可以通过悬停 var 关键字看到

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

我的问题是,有没有办法进行全局查找并将 var 替换为推断类型?

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

推荐答案

我认为 VS 2008(或 2010)没有这个功能,但是 ReSharper 具有用显式类型声明替换‘var’"context-action 您可以根据具体情况使用它来明确键入本地人.如果您想全力以赴,有一个代码清理"操作可用于对整个块/文件/项目/解决方案执行此重构.

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.

这篇关于VS2008 - 用推断类型替换 var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆