Browse Source

[CodeIssues] Be more allowing when picking format string arguments in FormatStringIssue.

newNRvisualizers
Simon Lindgren 13 years ago
parent
commit
1e561dd9b0
  1. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/FormatStringIssue.cs
  2. 21
      ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/FormatStringTests.cs

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/FormatStringIssue.cs

@ -126,7 +126,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -126,7 +126,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (parameter.Type.Equals(stringType) && parameterNames.Contains(parameter.Name) && argument is PrimitiveExpression) {
format = (string)((PrimitiveExpression)argument).Value;
formatStart = argument.StartLocation;
} else if (parameter.IsParams || parameter.Type.Equals(objectType)) {
} else if (format != null || parameter.IsParams) {
arguments.Add(argument);
}
}

21
ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/FormatStringTests.cs

@ -48,6 +48,27 @@ class TestClass @@ -48,6 +48,27 @@ class TestClass
var issues = GetIssues (new FormatStringIssue (), input, out context);
Assert.AreEqual (1, issues.Count);
}
[Test]
public void SupportsFixedArguments()
{
var input = @"
class TestClass
{
void Foo()
{
Bar(""{0}"", 1);
}
void Bar(string format, string arg0)
{
}
}";
TestRefactoringContext context;
var issues = GetIssues (new FormatStringIssue (), input, out context);
Assert.AreEqual (0, issues.Count);
}
[Test]
public void FormatItemIndexOutOfRangeOfArguments()

Loading…
Cancel
Save