自动将自引用添加到对象的属性

Automatically Add Self Reference To Properties Of Object

在 Visual Studio 2019 年,当编写 .net(C# 或 VB.net)时,有没有办法自动为对象的成员/属性加上各自的 "self" 引用前缀?

例如,在 c# 中,当从 class.

中引用 class 的成员时,自动在前面添加“this.

例如,在 VB.net 中,当从 class.

中引用 class 的成员时,自动在前面添加“me.

如果存在扩展名,则可以使用扩展名来执行此操作。

寻找Tools/Options/TextEditor/C#/代码风格 您会看到类似这样的首选项;

Qualify property access with 'this' | Do not prefer 'this'

更改上面的选项,瞧!

P.S: 你还需要运行 code cleanup(ctrl+K+E) 或设置severity为"Error",此时VS本身会提示"fix" 正如@stuartd 在评论中提到的那样