コンパイルしたC#コードを読み込もうとしています。
これは私のコードです:
using(OleDbCommand insertCommand = new OleDbCommand("...", connection))
{
// do super stuff
}
だが!
使用法がこれに変換されることは誰もが知っています:
{
OleDbCommand insertCommand = new OleDbCommand("...", connection)
try
{
//do super stuff
}
finally
{
if(insertCommand != null)
((IDisposable)insertCommand).Dispose();
}
}
(OleDbCommandは参照型であるため)。
しかし、アセンブリ(.NET 2.0でコンパイル)を逆コンパイルすると、Resharperで次のようになります。
try
{
insertCommand = new OleDbCommand("", connection);
Label_0017:
try
{
//do super stuff
}
finally
{
Label_0111:
if ((insertCommand == null) != null)
{
goto Label_0122;
}
insertCommand.Dispose();
Label_0122:;
}
私はこの行について話している:if ((insertCommand == null) != null)
。
insertCommandがnullだとしましょう。次に、最初の部分がtrueを返します。(true != null)
を返しますtrue
。それで、処分はまだスキップされますか?奇妙な、非常に奇妙な。
これをVisualStudioに貼り付けると、Resharperはすでに警告しています:式は常にtrueです...
ありがとう!
-クリストフ