Should these arguments be added or removed?

半腔热情 提交于 2019-11-27 16:08:55

Explicit parameter naming is optional on mandatory parameters, so both forms are "correct," the question is which do you like better? Like vcsjones said, Resharper is just giving you some refactoring options to suit your preferences.

Resharper tells me to

Actually, it doesn't. There are (broadly) two categories of things R# communicates to the user: things it thinks the user should do, and things that the user might want to do, that it can facilitate being done more quickly.

An example of the first:

var i = 4;
i = 5;
DoSomething(i);

The assignment of 4 will produce the "Assignment is not used" inspection, with a light bulb icon in the left margin, offering a quick-fix action to fix it (by removing the assignment).

An example of the second:

if ((new Random()).Next() > 5)
{
    DoSomething();
}
else
{
    DoSomethingElse();
}

Positioning the cursor on the if will produce a pencil icon in the left margin, offering a context action to invert the if. It's not saying you should - it's saying, "hey, if you want to do this, just select this menu item and I'll do it for you".

Adding an argument name is in the second category, a context action. If you don't want to be offered it, you can turn it off in ReSharper | Options | Code Editing | C# | Context Actions. For Code Inspections, the popup menu itself offers the opportunity to change the inspection severity; or you can look at all of them in ReSharper | Options | Code Isnpection | Inspection Severity.

Personally there are some context actions I don't think I've ever used (eg "convert to hex"), but there are others that I find invaluable for speedy coding (various combinations of switching between ?: and if and inverting, for example)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!