CA1500与SA1309 - 哪一个赢了? [英] CA1500 vs. SA1309 - Which one wins?

查看:378
本文介绍了CA1500与SA1309 - 哪一个赢了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会说,我明白,这两个代码分析和了StyleCop旨在为指导,许多人选择了反正忽略这些前缀。不过话说回来,我想看到​​的普遍共识是关于这两个规则是什么。

I'll prefix by saying that I understand that both Code Analysis and StyleCop are meant as guidelines, and many people chose to ignore these anyway. But having said that, I'd like to see what the general consensus is with regard to these two rules.

规则CA1500 说不做参数名称和私有字段名相同。

Rule CA1500 says don't make parameter names and private field names the same.

< A HREF =htt​​p://www.thewayithink.co.uk/stylecop/sa1309.htm>规则SA1309 ,从另一方面说,没有前缀的成员下划线或M _。

Rule SA1309, on the other hand, says don't prefix members with underscore or "m_".

这给我们留下了从相应的参数区分私人领域的支持很少的选项。乘坐这些例子

This leaves us with little options for distinguishing private backing fields from their corresponding parameters. Take these examples.

SA1309抱怨:

class SomeClass
{
    int _someField;

    public SomeClass(int someField)
    {
        this._someField = someField;
    }
}



CA1500抱怨:

CA1500 complains:

class SomeClass
{
    int someField;

    public SomeClass(int someField)
    {
        this.someField = someField;
    }
}



做什么选择我?我不想让私人支持字段PascalCase,因为这是(我相信相当普遍的)约定公共字段/属性。而且我不希望重命名一个或另一个,只是为了解决歧义的缘故。

What options do I have? I don't want to make the private backing field PascalCase, because this is the (I believe fairly universal) convention for public fields/properties. And I don't want to rename one or the other, just for the sake of resolving ambiguity.

所以我留下了上面的两个之一,这将需要我压抑的SA / CA规则之一。

So I'm left with one of the above two, which would require me to suppress one of the SA/CA rules.

你们有什么通常做什么?而更重要的,是什么做的这些规则的作者认为你应该做的(既不提供其文档中的替代解决方案)?

What do you guys typically do? And more importantly, what do the authors of these rules think you should do (as neither provide alternative solutions in their documentation)?

推荐答案

我们关闭SA1309。这背后的原因是相当弱的。

We turn off SA1309. The reasoning behind it is fairly weak.

我们的团队认为,首先是下划线私有成员的广为接受的做法远远超过想法可能有人在使用不同的编辑器该代码,这在我们的商店不会发生反正。作为提供立即差异化,下划线这是否也是如此。

Our team feels that the well-accepted practice of private members starting with underscores far outweighs the idea that someone might use a different editor on the code, which never happens in our shop anyway. As to providing an "immediate differentiation", the underscore does that as well.

如果你真的有仍然使用M_虽然开发商,你仍然需要检查这一点,你可以写只是一个快速的规则。

If you really have developers that still use "m_" though and you still need to check for that, you could write a quick rule for just that.

这篇关于CA1500与SA1309 - 哪一个赢了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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