Use Count instead of Any() on List (#18022)

This commit is contained in:
Kahbazi 2020-01-02 19:25:29 +03:30 committed by Chris Ross
parent 7ae6d1e379
commit b56f84131a
14 changed files with 22 additions and 22 deletions

View File

@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
: context.Database.GetMigrations()) : context.Database.GetMigrations())
.ToArray(); .ToArray();
if (pendingModelChanges || pendingMigrations.Any()) if (pendingModelChanges || pendingMigrations.Length > 0)
{ {
var page = new DatabaseErrorPage var page = new DatabaseErrorPage
{ {

View File

@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Diagnostics.HealthChecks
private static IDictionary<HealthStatus, int> ValidateStatusCodesMapping(IDictionary<HealthStatus,int> mapping) private static IDictionary<HealthStatus, int> ValidateStatusCodesMapping(IDictionary<HealthStatus,int> mapping)
{ {
var missingHealthStatus = ((HealthStatus[])Enum.GetValues(typeof(HealthStatus))).Except(mapping.Keys).ToList(); var missingHealthStatus = ((HealthStatus[])Enum.GetValues(typeof(HealthStatus))).Except(mapping.Keys).ToList();
if (missingHealthStatus.Any()) if (missingHealthStatus.Count > 0)
{ {
var missing = string.Join(", ", missingHealthStatus.Select(status => $"{nameof(HealthStatus)}.{status}")); var missing = string.Join(", ", missingHealthStatus.Select(status => $"{nameof(HealthStatus)}.{status}"));
var message = var message =

View File

@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.ResponseCompression
return null; return null;
} }
if (!StringWithQualityHeaderValue.TryParseList(accept, out var encodings) || !encodings.Any()) if (!StringWithQualityHeaderValue.TryParseList(accept, out var encodings) || encodings.Count == 0)
{ {
_logger.NoAcceptEncoding(); _logger.NoAcceptEncoding();
return null; return null;

View File

@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
attributeRoutingConfigurationErrors); attributeRoutingConfigurationErrors);
} }
if (attributeRoutingConfigurationErrors.Any()) if (attributeRoutingConfigurationErrors.Count > 0)
{ {
var message = CreateAttributeRoutingAggregateErrorMessage(attributeRoutingConfigurationErrors.Values); var message = CreateAttributeRoutingAggregateErrorMessage(attributeRoutingConfigurationErrors.Values);
@ -114,13 +114,13 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
} }
var namedRoutedErrors = ValidateNamedAttributeRoutedActions(actionsByRouteName); var namedRoutedErrors = ValidateNamedAttributeRoutedActions(actionsByRouteName);
if (namedRoutedErrors.Any()) if (namedRoutedErrors.Count > 0)
{ {
var message = CreateAttributeRoutingAggregateErrorMessage(namedRoutedErrors); var message = CreateAttributeRoutingAggregateErrorMessage(namedRoutedErrors);
throw new InvalidOperationException(message); throw new InvalidOperationException(message);
} }
if (routeTemplateErrors.Any()) if (routeTemplateErrors.Count > 0)
{ {
var message = CreateAttributeRoutingAggregateErrorMessage(routeTemplateErrors); var message = CreateAttributeRoutingAggregateErrorMessage(routeTemplateErrors);
throw new InvalidOperationException(message); throw new InvalidOperationException(message);

View File

@ -260,7 +260,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
PreconditionState matchFoundState, PreconditionState matchFoundState,
PreconditionState matchNotFoundState) PreconditionState matchNotFoundState)
{ {
if (etagHeader != null && etagHeader.Any()) if (etagHeader?.Count > 0)
{ {
var state = matchNotFoundState; var state = matchNotFoundState;
foreach (var entityTag in etagHeader) foreach (var entityTag in etagHeader)

View File

@ -277,7 +277,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
listOfClasses.RemoveAll(x => x.Equals(encodedClassValue)); listOfClasses.RemoveAll(x => x.Equals(encodedClassValue));
if (listOfClasses.Any()) if (listOfClasses.Count > 0)
{ {
var joinedClasses = new HtmlString(string.Join(" ", listOfClasses)); var joinedClasses = new HtmlString(string.Join(" ", listOfClasses));
tagHelperOutput.Attributes.SetAttribute(classAttribute.Name, joinedClasses); tagHelperOutput.Attributes.SetAttribute(classAttribute.Name, joinedClasses);

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Authorization
throw new ArgumentNullException(nameof(authenticationSchemes)); throw new ArgumentNullException(nameof(authenticationSchemes));
} }
if (requirements.Count() == 0) if (!requirements.Any())
{ {
throw new InvalidOperationException(Resources.Exception_AuthorizationPolicyEmpty); throw new InvalidOperationException(Resources.Exception_AuthorizationPolicyEmpty);
} }
@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Authorization
} }
var rolesSplit = authorizeDatum.Roles?.Split(','); var rolesSplit = authorizeDatum.Roles?.Split(',');
if (rolesSplit != null && rolesSplit.Any()) if (rolesSplit?.Length > 0)
{ {
var trimmedRolesSplit = rolesSplit.Where(r => !string.IsNullOrWhiteSpace(r)).Select(r => r.Trim()); var trimmedRolesSplit = rolesSplit.Where(r => !string.IsNullOrWhiteSpace(r)).Select(r => r.Trim());
policyBuilder.RequireRole(trimmedRolesSplit); policyBuilder.RequireRole(trimmedRolesSplit);
@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Authorization
} }
var authTypesSplit = authorizeDatum.AuthenticationSchemes?.Split(','); var authTypesSplit = authorizeDatum.AuthenticationSchemes?.Split(',');
if (authTypesSplit != null && authTypesSplit.Any()) if (authTypesSplit?.Length > 0)
{ {
foreach (var authType in authTypesSplit) foreach (var authType in authTypesSplit)
{ {

View File

@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Authorization.Infrastructure
throw new ArgumentNullException(nameof(allowedRoles)); throw new ArgumentNullException(nameof(allowedRoles));
} }
if (allowedRoles.Count() == 0) if (!allowedRoles.Any())
{ {
throw new InvalidOperationException(Resources.Exception_RoleRequirementEmpty); throw new InvalidOperationException(Resources.Exception_RoleRequirementEmpty);
} }

View File

@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Authorization
if (authorizeResult.Challenged) if (authorizeResult.Challenged)
{ {
if (policy.AuthenticationSchemes.Any()) if (policy.AuthenticationSchemes.Count > 0)
{ {
foreach (var scheme in policy.AuthenticationSchemes) foreach (var scheme in policy.AuthenticationSchemes)
{ {
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Authorization
} }
else if (authorizeResult.Forbidden) else if (authorizeResult.Forbidden)
{ {
if (policy.AuthenticationSchemes.Any()) if (policy.AuthenticationSchemes.Count > 0)
{ {
foreach (var scheme in policy.AuthenticationSchemes) foreach (var scheme in policy.AuthenticationSchemes)
{ {

View File

@ -119,7 +119,7 @@ namespace System.Buffers
MemoryPoolThrowHelper.ThrowInvalidOperationException_DisposingPoolWithActiveBlocks(_totalBlocks - _blocks.Count, _totalBlocks, _blocks.ToArray()); MemoryPoolThrowHelper.ThrowInvalidOperationException_DisposingPoolWithActiveBlocks(_totalBlocks - _blocks.Count, _totalBlocks, _blocks.ToArray());
} }
if (_blockAccessExceptions.Any()) if (_blockAccessExceptions.Count > 0)
{ {
throw CreateAccessExceptions(); throw CreateAccessExceptions();
} }
@ -136,7 +136,7 @@ namespace System.Buffers
private void SetAllBlocksReturned() private void SetAllBlocksReturned()
{ {
if (_blockAccessExceptions.Any()) if (_blockAccessExceptions.Count > 0)
{ {
_allBlocksReturned.SetException(CreateAccessExceptions()); _allBlocksReturned.SetException(CreateAccessExceptions());
} }

View File

@ -752,7 +752,7 @@ namespace Microsoft.AspNetCore.Certificates.Generation
result.ResultCode = EnsureCertificateResult.Succeeded; result.ResultCode = EnsureCertificateResult.Succeeded;
X509Certificate2 certificate = null; X509Certificate2 certificate = null;
if (certificates.Count() > 0) if (certificates.Any())
{ {
result.Diagnostics.Debug("Found valid certificates present on the machine."); result.Diagnostics.Debug("Found valid certificates present on the machine.");
result.Diagnostics.Debug(result.Diagnostics.DescribeCertificates(certificates)); result.Diagnostics.Debug(result.Diagnostics.DescribeCertificates(certificates));

View File

@ -489,7 +489,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
private Task<bool> IsHubMethodAuthorized(IServiceProvider provider, HubConnectionContext hubConnectionContext, IList<IAuthorizeData> policies, string hubMethodName, object[] hubMethodArguments) private Task<bool> IsHubMethodAuthorized(IServiceProvider provider, HubConnectionContext hubConnectionContext, IList<IAuthorizeData> policies, string hubMethodName, object[] hubMethodArguments)
{ {
// If there are no policies we don't need to run auth // If there are no policies we don't need to run auth
if (!policies.Any()) if (policies.Count == 0)
{ {
return TaskCache.True; return TaskCache.True;
} }

View File

@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
var genericTypeNames = var genericTypeNames =
paramTypes.Where(p => p.IsGenericParameter).Select(p => p.Name).Distinct().ToArray(); paramTypes.Where(p => p.IsGenericParameter).Select(p => p.Name).Distinct().ToArray();
if (genericTypeNames.Any()) if (genericTypeNames.Length > 0)
{ {
methodBuilder.DefineGenericParameters(genericTypeNames); methodBuilder.DefineGenericParameters(genericTypeNames);
} }

View File

@ -159,7 +159,7 @@ namespace Microsoft.DotNet.OpenApi.Commands
var items = project.GetItems(tagName); var items = project.GetItems(tagName);
var fileItems = items.Where(i => string.Equals(GetFullPath(i.EvaluatedInclude), GetFullPath(sourceFile), StringComparison.Ordinal)); var fileItems = items.Where(i => string.Equals(GetFullPath(i.EvaluatedInclude), GetFullPath(sourceFile), StringComparison.Ordinal));
if (fileItems.Count() > 0) if (fileItems.Any())
{ {
Warning.Write($"One or more references to {sourceFile} already exist in '{project.FullPath}'. Duplicate references could lead to unexpected behavior."); Warning.Write($"One or more references to {sourceFile} already exist in '{project.FullPath}'. Duplicate references could lead to unexpected behavior.");
return; return;
@ -376,7 +376,7 @@ namespace Microsoft.DotNet.OpenApi.Commands
else else
{ {
var uri = new Uri(url); var uri = new Uri(url);
if (uri.Segments.Count() > 0 && uri.Segments.Last() != "/") if (uri.Segments.Any() && uri.Segments.Last() != "/")
{ {
var lastSegment = uri.Segments.Last(); var lastSegment = uri.Segments.Last();
if (!Path.HasExtension(lastSegment)) if (!Path.HasExtension(lastSegment))