简体   繁体   English

比较字符串为null - 为什么Resharper认为这总是假的?

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

I have this code in my custom MembershipProvider: 我在自定义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标记了第二个if-Statement并且告诉我,它总是评估为false。

resharper消息

But why would this always evaluate to false? 但为什么这总是评价为假? I could easily pass null to the method as a parameter. 我可以轻松地将null作为参数传递给方法。

Is this a bug or is Resharper right here? 这是一个错误还是Resharper就在这里?

PS 1: I use Resharper 6.1 PS 1:我使用Resharper 6.1
PS 2: I know using string.IsNullOrEmpty() would be the way to go here anyway. PS 2:我知道使用string.IsNullOrEmpty()无论如何都要去这里。 I'm just curious. 我只是好奇。

Probably, the argument name is marked as [NotNull] . 可能,参数name标记为[NotNull] Resharper ships with contract metadata for common BCL classes. Resharper附带了常见BCL类的合同元数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM