Why does ReSharper think that “thread.Name == null” is always false? [closed]

笑着哭i 提交于 2020-01-03 08:49:02

问题


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

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