本地 const 变量应该以大写字母还是小写字母开头
StyleCop 和 Resharper 之间存在风格冲突。 Stylecop 1303 说 const vars 应该以大写开头,我同意。 Resharper 对类范围的 const 声明表示可以,但是当在本地(例如方法)作用域中使用 const 时,Reshaper 不赞成并希望将所有内容都采用驼峰命名法。
当然,在 R# 中禁用此规则没有问题,但此规则背后的原因可能是什么?有人有什么想法吗?
Got a style conflict between StyleCop and Resharper.
Stylecop 1303 says that const vars should start uppercase and I agree.
Resharper says OK for class-wide const declarations, but when using a const in a local (e.g. method) scope, Reshaper doesn't approve and wants to make everything camelCasing.
Of course no problem to disable this rule in R#, but what could be the reason behind this rule? Anyone any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您下载 Stylecop for Resharper,那么它会附带一个 Resharper 设置文件,可以为您解决此问题。这也是让 Resharper 帮助您实现 Stylecop 合规性的好方法:
http://stylecopforresharper.codeplex.com/
If you download Stylecop for Resharper then it comes with a Resharper settings file that will fix this for you. It's also a great way to get Resharper to help you with Stylecop compliance:
http://stylecopforresharper.codeplex.com/
在这种情况下,我会坚持 R# 解释(在本地范围内,一切都应该是 lowerCamelCase)。
这很大程度上是一个习惯问题,因为我通常从一个变量开始,在完成该方法后,如果相应的 R# 智能标记向我推荐的话,我可能会将 var 更改为 const。
但正如所指出的,重要的是整个团队保持一致......
托马斯
I'd stick to the R# interpretation in this case (on local scope, everything should be lowerCamelCase).
It's largely a matter of habit, because I'm usually starting with a variable, and after I've finished the method, I might change the var to a const, if the respective R# smart tag recommends this to me.
But as pointed out, the important thing is to be consistent across the team...
Thomas
我认为 StyleCope 使用大小写来区分类和方法范围。
I think StyleCope is using the case to distinguish between class and method scope.
我相信几乎每个人都对此有想法,但这些想法很少是同步的。找到你的口味并坚持下去。 Re#之类的都是建议。您和您的同事应该在某些事情上达成一致,这是最重要的。
I'm sure almost everyone has thoughts on that, and those are seldom in sync. Find your flavor and stick with it. Re# and the like are suggestions. You and your coworkers should agree on something, that is most important.