6

Resharper が自分自身と議論するとき、どのペルソナをより信用するべきかをどうやって知るのでしょうか?

Resharper を混乱させるコードをいくつか見つけたと思います (これは明らかに非常に珍しいケースです。1 日使用した後、Resharper はミツバチの膝/液化パン以来の最大のものだと思います)。

このコード行で:

ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));

Resharper は、「引数名 'rgbkey' を追加」してから、 「引数名 'rgbIV' を追加」するように指示します

したがって、行は次のようになります。

ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(rgbKey: SecretKey.GetBytes(32), rgbIV: SecretKey.GetBytes(16));

ただし、Resharper を再度実行すると、次のように表示されます。

「冗長な引数名指定」-「引数名指定の削除」(rgbkey) (さらにrgbIV)。

どちらでもうまくいくように見えますが...

4

2 に答える 2

6

明示的なパラメータの命名は必須パラメータではオプションであるため、どちらの形式も「正しい」ので、どちらが好きですか。vcsjonesが言ったように、Resharperはあなたの好みに合うようにあなたにいくつかのリファクタリングオプションを提供しているだけです。

于 2012-06-08T18:04:22.720 に答える
6

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)

于 2012-06-11T08:31:39.810 に答える