diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/StringIsNullOrEmptyIssue.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/StringIsNullOrEmptyIssue.cs
index a3cc5237a2..12016f7907 100644
--- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/StringIsNullOrEmptyIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/StringIsNullOrEmptyIssue.cs
@@ -31,7 +31,7 @@ using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
///
- /// Checks for str == null && str == ""
+ /// Checks for str == null && str == " "
/// Converts to: string.IsNullOrEmpty (str)
///
[IssueDescription("Use string.IsNullOrEmpty",
@@ -124,6 +124,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
if (m.Success) {
var str = m.Get("str").Single();
+ var def = ctx.Resolve (str).Type.GetDefinition ();
+ if (def == null || def.KnownTypeCode != ICSharpCode.NRefactory.TypeSystem.KnownTypeCode.String)
+ return;
AddIssue(binaryOperatorExpression, ctx.TranslateString("Use string.IsNullOrEmpty"), script => {
Expression expr = new PrimitiveType ("string").Invoke("IsNullOrEmpty", str.Clone());
if (isNegated)
diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/StringIsNullOrEmptyInspectorTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/StringIsNullOrEmptyInspectorTests.cs
index d256ca5682..28f6431a58 100644
--- a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/StringIsNullOrEmptyInspectorTests.cs
+++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/StringIsNullOrEmptyInspectorTests.cs
@@ -499,5 +499,23 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues
}
}");
}
+
+ [Test]
+ public void TestArrays ()
+ {
+ var input = @"class Foo
+{
+ void Bar ()
+ {
+ int[] foo = new int[10];
+ if (foo == null || foo.Length == 0) {
+ }
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues (new StringIsNullOrEmptyIssue (), input, out context);
+ Assert.AreEqual (0, issues.Count);
+ }
}
}