Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare string to null - Why does Resharper think this is always false?

I have this code in my custom MembershipProvider:

public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
    if (config == null)
        throw new ArgumentNullException("config");

    if (name == null)
        name = "MyCustomMembershipProvider";
    ...
}

Resharper marks the second if-Statement and tells me, it would always evaluate to false.

resharper message

But why would this always evaluate to false? I could easily pass null to the method as a parameter.

Is this a bug or is Resharper right here?

PS 1: I use Resharper 6.1
PS 2: I know using string.IsNullOrEmpty() would be the way to go here anyway. I'm just curious.

like image 549
magnattic Avatar asked Jul 17 '12 19:07

magnattic


1 Answers

Probably, the argument name is marked as [NotNull]. Resharper ships with contract metadata for common BCL classes.

like image 195
usr Avatar answered Oct 06 '22 00:10

usr