Why does StyleCop recommend prefixing method or property calls with “this”?

前端 未结 9 2121
孤街浪徒
孤街浪徒 2020-11-27 04:15

I have been trying to follow StyleCop\'s guidelines on a project, to see if the resulting code was better in the end. Most rules are reasonable or a matter of opinion on cod

9条回答
  •  生来不讨喜
    2020-11-27 04:29

    I don't really follow this guidance unless I'm in the scenarios you need it:

    • there is an actual ambiguity - mainly this impacts either constructors (this.name = name;) or things like Equals (return this.id == other.id;)
    • you want to pass a reference to the current instance
    • you want to call an extension method on the current instance

    Other than that I consider this clutter. So I turn the rule off.

提交回复
热议问题