ReSharper的和VAR [英] ReSharper and var

查看:208
本文介绍了ReSharper的和VAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/1873873/why-does-resharper-want-to-use-var-for-everything">Why没有ReSharper的想用无功的一切?

我有ReSharper的4.5,并发现它非常宝贵的,到目前为止,但我有一个问题;它似乎想使每一个变量声明隐(VAR)。作为一个相对的的开发者,我应该有多少信任ReSharper的,当涉及到这一点?采取下面的code段从绘制标签头的方法。

I have ReSharper 4.5 and have found it invaluable so far but I have a concern; It seems to want to make every variable declaration implicit(var). As a relatively new developer how much should I trust ReSharper when it comes to this? Take the below code snippet from a method that Paints Tab Headers.

TabPage currentTab = tabCaseNotes.TabPages[e.Index];
Rectangle itemRect = tabCaseNotes.GetTabRect(e.Index);
SolidBrush fillBrush = new SolidBrush(Color.Linen);
SolidBrush textBrush = new SolidBrush(Color.Black);
StringFormat sf = new StringFormat
{
    Alignment = StringAlignment.Center,
    LineAlignment = StringAlignment.Center
};

ReSharper的要我改变所有这些5到的无功的。我已阅读下列类似的帖子,在C#中使用 var关键字的,但我想知道从ReSharper的角度来看。

Resharper wants me to change all 5 of those to var. I have read the following similar post, Use of var keyword in C#, but I would like to know from a ReSharper standpoint.

谢谢!

推荐答案

您不需要有型的线条,使其更具可读性,个人preference它的问题。我喜欢的VAR变化:

You don't need to have the type in the line to make it more readable, its a matter of personal preference. I do like the var variation:

var currentTab = tabCaseNotes.TabPages[e.Index];
var itemRect = tabCaseNotes.GetTabRect(e.Index);
var fillBrush = new SolidBrush(Color.Linen);
var textBrush = new SolidBrush(Color.Black);
var sf = new StringFormat
   {
      Alignment = StringAlignment.Center,
      LineAlignment = StringAlignment.Center
   };

更新:我将添加一个有争议的观点就可以了。除非我读code从一本书,我通常不关心什么具体类型对于理解code一些行我读。考虑.GetTableRectangle(e.Index),对此你是不是显示了code,工作就可以了:

Update: I will add a controversial view on it. Unless I am reading code from a book, I don't usually care what's the specific type for understanding some lines of code I am reading. Consider the .GetTableRectangle(e.Index), for which you are not showing the code that operates on it:

var itemRect = tabCaseNotes.GetTableRectangle(e.Index);
//do some operations on itemRect

在阅读特定code,我会得到更多的去了解它从itemRect的操作不是来自于它的类型。它可以是IRectangle,矩形,CustomRectangle,并且仍然不会多说什么了code是干嘛用的。相反,我更关心的itemRect.Height,itemRect.Width或itemRect.GetArea()以及所涉及的逻辑。

While reading that specific code I will get more to understand it from the operations on itemRect than from its type. It can be IRectangle, Rectangle, CustomRectangle, and still won't say much on what the code is doing with it. Instead I care more for the itemRect.Height, itemRect.Width or itemRect.GetArea() along with the logic involved.

更新2:正如其他人所指出的,你可以将其关闭。确保让球队以相同的做法,或者你可能会结束与更改,每次不同的人接触到code的一种方式或其他。参见:<一href="http://www.jetbrains.com/resharper/features/$c$cTemplate.html">http://www.jetbrains.com/resharper/features/$c$cTemplate.html

Update 2: As others have pointed out you can turn it off. Make sure to keep the team with the same practices, or you will probably end up with making changes one way or the other each time a different person touches the code. See: http://www.jetbrains.com/resharper/features/codeTemplate.html

这篇关于ReSharper的和VAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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