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

徘徊边缘 提交于 2019-12-04 18:41:26

问题


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.

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.


回答1:


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



来源:https://stackoverflow.com/questions/11529726/compare-string-to-null-why-does-resharper-think-this-is-always-false

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