为什么 Resharper 重命名变量以下划线开头?
我从来没有理解这一点,坦率地说,在代码中看到它让我很生气:以下划线开头的变量名称。
这有什么意义呢?
我刚刚安装了 Resharper 5.1,尝试了一下,看起来不错,尽管这一件事对我来说毁了它。
我还没有检查过,但我希望我能把它关掉。但为什么首先要这样做呢?
I've never understood this, and frankly, it pisses me off to see it in code: variable names that begin with an underscore.
What is the point of this?
I've just installed Resharper 5.1, trying it out and it seems nice, though this one thing is ruining it for me.
I haven't checked, but I'm hoping I can turn it off. But why is it done in the first place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是私有字段的一种非常常见的样式,有些使用
m_lowerCamelCase
,有些仅使用_lowerCamelCase
,还有一些使用lowerCamelCase
。对于函数内部的变量来说,它更加罕见,并且默认使用lowerCamelCase
来重塑它们。请注意,设计指南的命名部分不鼓励使用前缀公共成员但私有成员不关心(并且公共字段应该仅在真正特定的情况下使用,因为无论如何它们都是危险的)。
在重塑器选项中,所有这些都可以用语言>进行更改。常见>命名风格。
您还可以将参数保存在解决方案或文件中并导入/导出它们。使用它,您可以为团队中的每个人一次性设置参数。
It's a pretty common style for private fields, some use
m_lowerCamelCase
, others only_lowerCamelCase
and still otherslowerCamelCase
. For variables inside a functions it's a lot more rare and reshaper by default uselowerCamelCase
for them.Note that the naming section of the design guidelines discourage the use of prefixes for public members but private members are not concerned (And public fields should be used only in really specific cases due to their dangers anyway).
In the reshaper options all of that could be changed in Languages > Common > Naming Style.
You could also save your parameters in the solution or in a file and import/export them. Using that you could set the parameters once and for all for everyone in your team.
用下划线作为私有实例和/或各种静态成员的前缀是一种广泛采用的做法(显然,[需要引用],但确实如此);这里不是我讨论其是非的地方。
在 ReSharper 中 |选项您将看到
语言|常见 |命名样式(以及每种语言的覆盖)将允许您指示 ReSharper 完全按照您的意愿进行操作。
Prefixing private instance and/or static members of various kinds with an underscore is a widely-adopted practice ([citation needed], obviously, but it is); this is not the place for me to discuss its rights and wrongs.
In
ReSharper | Options
you will seeLanguages | Common | Naming Style
(and per-language overrides) that will allow you to instruct ReSharper to do exactly as you wish instead.使用下划线来表示类变量是一种常见的做法。
ReSharper 中应该有一个选项来配置您希望类变量开始的内容(如果有的话)。我没有在这台机器上安装它,所以我无法轻松检查该选项是什么。
It's a common practice to use underscores to denote class variables.
There should be an option in ReSharper to configure what, if anything, you want your class variables to start with. I don't have it installed on this machine so I can't easily check what that option is.