Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Handle array types correctly in ReviewLinqMethodRule. FIx bnc664556
Browse files Browse the repository at this point in the history
* ReviewLinqMethodRule.cs: Handle array types correctly
* Test/ReviewLinqMethodTest.cs: Test case for above. Provided by Antoine
Vandecreme  <ant.vand@gmail.com>
  • Loading branch information
Sebastien Pouliot committed Jan 23, 2011
1 parent 1166178 commit bca1cb2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gendarme/AUTHORS
Expand Up @@ -16,7 +16,7 @@ Andres G. Aragoneses <aaragoneses@novell.com>
Peter Johanson <peter@peterjohanson.com>
Jesse Jones <jesjones@mindspring.com>
Rolf Bjarne Kvinge <RKvinge@novell.com>
Antoine Vandecreme <avandecreme@sopragroup.com>
Antoine Vandecreme <ant.vand@gmail.com>
Julien Hoarau <madgnome@gmail.com>
N Lum <nol888@gmail.com>
Nicholas Rioux <nickr500@gmail.com>
Expand Down
Expand Up @@ -124,7 +124,8 @@ private void CheckForCountProperty (TypeReference type, MethodDefinition method,
Log.WriteLine (this, "{0:X4} {1}", ins.Offset, message);
Runner.Report (method, ins, Severity.Medium, Confidence.High, message);

} else if (HasMethod (type, LengthProperty)) {
} else if (type.IsArray || HasMethod (type, LengthProperty)) {
// note: arrays [] always have a Length property but resolving arrays return the element type
string message = "Use the Length property instead of the Count () method.";
Log.WriteLine (this, "{0:X4} {1}", ins.Offset, message);
Runner.Report (method, ins, Severity.Medium, Confidence.High, message);
Expand Down
Expand Up @@ -293,5 +293,18 @@ public void Cases ()

AssertRuleSuccess<Bug656790> ("CanExecute");
}

class Bug664556 {
public int DoSomething (Bug664556 [] ic)
{
return ic.Count ();
}
}

[Test]
public void Array ()
{
AssertRuleFailure<Bug664556> ("DoSomething", 1);
}
}
}

0 comments on commit bca1cb2

Please sign in to comment.