Skip to content

Commit

Permalink
Enable CA1827 (use Any() instead of Count() compared to 0) (dotnet#31983
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stephentoub authored Feb 9, 2020
1 parent 3467e97 commit 5d9c9da
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<Rule Id="CA1819" Action="None" /> <!-- Properties should not return arrays -->
<Rule Id="CA1820" Action="None" /> <!-- Test for empty strings using string length -->
<Rule Id="CA1822" Action="None" /> <!-- Mark members as static -->
<Rule Id="CA1827" Action="None" /> <!-- Do not use Count() when Any() can be used -->
<Rule Id="CA2000" Action="None" /> <!-- Dispose objects before losing scope -->
<Rule Id="CA2002" Action="None" /> <!-- Do not lock on objects with weak identity -->
<Rule Id="CA2010" Action="None" /> <!-- Always consume the value returned by methods marked with PreserveSigAttribute -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public override string ToString()
sb.Append(string.Format("\n\tRequiredCreationPolicy\t{0}", RequiredCreationPolicy));
}

if (_requiredMetadata.Count() > 0)
if (_requiredMetadata.Any())
{
sb.Append("\n\tRequiredMetadata");
foreach (KeyValuePair<string, Type> metadataItem in _requiredMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ internal bool BuildConstructorAttributes(Type type, ref List<Tuple<object, List<
foreach (ConstructorInfo ci in constructors)
{
// We have a constructor configuration we must log a warning then not bother with ConstructorAttributes
IEnumerable<Attribute> attributes = Attribute.GetCustomAttributes(ci, typeof(ImportingConstructorAttribute), false);
if (attributes.Count() != 0)
Attribute[] attributes = Attribute.GetCustomAttributes(ci, typeof(ImportingConstructorAttribute), false);
if (attributes.Length != 0)
{
CompositionTrace.Registration_ConstructorConventionOverridden(type);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private void ValidateCombinedSet(DBConnectionString componentSet, DBConnectionSt
// Component==Allow, Combined==Allow
// All values in the Combined Set should also be in the Component Set
// Combined - Component == null
Debug.Assert(combinedSet._restrictionValues.Except(componentSet._restrictionValues).Count() == 0, "Combined set allows values not allowed by component set");
Debug.Assert(!combinedSet._restrictionValues.Except(componentSet._restrictionValues).Any(), "Combined set allows values not allowed by component set");
}
else if (combinedSet._behavior == KeyRestrictionBehavior.PreventUsage)
{
Expand All @@ -326,14 +326,14 @@ private void ValidateCombinedSet(DBConnectionString componentSet, DBConnectionSt
// Component==PreventUsage, Combined==Allow
// There shouldn't be any of the values from the Component Set in the Combined Set
// Intersect(Component, Combined) == null
Debug.Assert(combinedSet._restrictionValues.Intersect(componentSet._restrictionValues).Count() == 0, "Combined values allows values prevented by component set");
Debug.Assert(!combinedSet._restrictionValues.Intersect(componentSet._restrictionValues).Any(), "Combined values allows values prevented by component set");
}
else if (combinedSet._behavior == KeyRestrictionBehavior.PreventUsage)
{
// Component==PreventUsage, Combined==PreventUsage
// All values in the Component Set should also be in the Combined Set
// Component - Combined == null
Debug.Assert(componentSet._restrictionValues.Except(combinedSet._restrictionValues).Count() == 0, "Combined values does not prevent all of the values prevented by the component set");
Debug.Assert(!componentSet._restrictionValues.Except(combinedSet._restrictionValues).Any(), "Combined values does not prevent all of the values prevented by the component set");
}
else
{
Expand Down

0 comments on commit 5d9c9da

Please sign in to comment.