【发布时间】:2010-09-07 22:24:42
【问题描述】:
StyleCop 有一条关于使用“this”的规则。调用类成员的前缀 (SA1101)。
这条规则是否适用于从其基类继承的类的成员(例如方法)。
例子:
class BaseClass
{
protected void F1()
{
...
}
}
class ChildClass : BaseClass
{
protected void F2()
{
...
}
protected void F3()
{
this.F2(); // This is correct acording to SA1101
// F1 is a member of base class and if I dont put this prefix, stylecop will not show any message.
this.F1(); // Is this correct?
F1(); // Or this?
}
}
我知道这只是为了提高可读性。
【问题讨论】:
-
好吧,那么在我的优先级列表中尝试 StyleCop 就完蛋了。
-
@Jon Hanna:您可以配置实际运行的规则。在您查看并确定哪些规则对您重要/有用之前,我不会打折 StyleCop。
-
@A. Karimi 不是为了可读性,实际上使用 base 会使代码更具可读性,它是为了避免错误。该文档有很好的示例和解释stylecop.soyuz5.com/SA1100.html
标签: c# coding-style this stylecop