问题
I am writing a helper method for conveniently setting the Name
of a Thread
:
public static bool TrySetName(this Thread thread, string name)
{
try
{
if (thread.Name == null)
{
thread.Name = name;
return true;
}
return false;
}
catch (InvalidOperationException)
{
return false;
}
}
It's working as intended. ReSharper, however, claims that the condition is always false and the corresponding code is heuristically unreachable. That's wrong. A Thread.Name
is always null until a string is assigned.
So, why does ReSharper think it is? And is there some way to tell ReSharper it isn't (other than // ReSharper disable ...
)?
I'm using ReSharper 5.1.3.
回答1:
This was fixed in 6+ of RS I think. See here.
回答2:
It appears to be a bug in R#, fixed in v6.
see: http://devnet.jetbrains.net/message/5366898
来源:https://stackoverflow.com/questions/13199043/why-does-resharper-think-that-thread-name-null-is-always-false