StyleCop有一條關於使用「this」的規則。前綴到呼叫類成員(SA1101)。C#StyleCop - 使用「this」。基類成員的前綴,如當前類成員或不是?
此規則適用於從其基類繼承的類的成員(例如方法)。
例子:
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的方式嘗試了我的優先事項列表,然後。 – 2010-09-08 00:56:21
@Jon Hanna:您可以配置哪些規則實際運行。我不會打折StyleCop,直到你看看它,並決定哪些規則對你很重要/有用。 – 2010-09-08 22:32:46
@A。Karimi它不是爲了可讀性,實際上使用** base **會使代碼更具可讀性,它是爲了避免錯誤。該文檔有很好的示例和解釋http://stylecop.soyuz5.com/SA1100.html – 2013-05-16 17:02:47