3

Is there a way to tell Visual Studio to make qualifying members of the current instance with this. mandatory? I prefer the clarity.

Details:

In C#, if you have instance members (fields, properties, methods, etc.), normally you can refer to them both with and without this, e.g.:

class Foo
{
    private int bar;

    Foo()
    {
        // These two lines are both valid, and both do exactly the same thing
        bar = 42;
        this.bar = 42;
    }
}

In my coding style, I don't want this to optional, I want the first line above to cause at least a warning. Obviously this is just for my own purposes, I'm not trying to mark the resulting assembly in some way that requires people using it to also do this, this is purely a personal style thing.

4

2 回答 2

6

您可以使用Resharper(使用此处描述的设置)和StyleCop(使用此规则)等程序。

它们允许您定义自己的编码样式,这些样式会在您的代码中引起验证警告,并提供有关解决这些问题的建议。

这是一个关于 resharper 的免费替代品的问题。

reshaper 有哪些替代品?

于 2012-12-09T10:05:49.423 回答
1

StyleCop 似乎默认开启了这个规则。

于 2012-12-09T10:17:33.887 回答