Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 336
Sebastian Negraszus Avatar asked Nov 02 '12 16:11

Sebastian Negraszus


2 Answers

This was fixed in 6+ of RS I think. See here.

like image 147
Nick Avatar answered Nov 11 '22 20:11

Nick


It appears to be a bug in R#, fixed in v6.

see: http://devnet.jetbrains.net/message/5366898

like image 33
Steve Avatar answered Nov 11 '22 20:11

Steve