1

使用 Resharper 7.1.3、Visual Studio 2012、.net 4:

这段代码:

    string str = null;
    str = System.Web.HttpUtility.HtmlEncode(str); 

生成警告:“可能对标记为 NotNull 属性的实体分配空值”。但是当我使用 Reflector 查看 HttpUtility.HtmlEncode 的代码时,看起来代码最终会检查空字符串,并在这种情况下立即退出。这是 Resharper (?) 弄错的情况之一吗?或者是支票,例如:

if (str != null)
   str = System.Web.HttpUtility.HtmlEncode(str);   

真的有必要吗?

4

0 回答 0