比较字符串空 - 为什么ReSharper的认为这始终是假的? [英] Compare string to null - Why does Resharper think this is always false?

查看:169
本文介绍了比较字符串空 - 为什么ReSharper的认为这始终是假的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的自定义的MembershipProvider这个code:

 公众覆盖无效初始化(字符串名称,System.Collections.Specialized.NameValueCollection配置)
{
    如果(配置== NULL)
        抛出新ArgumentNullException(配置);

    如果(名称== NULL)
        NAME =MyCustomMembershipProvider;
    ...
}
 

ReSharper的,标志着第二if语句,并告诉我,这将总是为false。

但是,为什么这总是为假?我可以很容易地传递null方法作为参数。<​​/ P>

这是一个bug或者是ReSharper的就在这里?

PS 1:我用ReSharper的6.1
PS 2:我知道用string.IsNullOrEmpty()是要走的路在这里反正。我只是好奇。

解决方案

也许,参数名称标记为 [NOTNULL] 。 ReSharper的船舶合同的元数据,共同BCL类。

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.

解决方案

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

这篇关于比较字符串空 - 为什么ReSharper的认为这始终是假的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆