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())
.ToArray();
if (pendingModelChanges || pendingMigrations.Any())
if (pendingModelChanges || pendingMigrations.Length > 0)
{
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)
{
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 message =

View File

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

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Authorization
throw new ArgumentNullException(nameof(authenticationSchemes));
}
if (requirements.Count() == 0)
if (!requirements.Any())
{
throw new InvalidOperationException(Resources.Exception_AuthorizationPolicyEmpty);
}
@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Authorization
}
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());
policyBuilder.RequireRole(trimmedRolesSplit);
@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Authorization
}
var authTypesSplit = authorizeDatum.AuthenticationSchemes?.Split(',');
if (authTypesSplit != null && authTypesSplit.Any())
if (authTypesSplit?.Length > 0)
{
foreach (var authType in authTypesSplit)
{

View File

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

View File

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

View File

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

View File

@ -752,7 +752,7 @@ namespace Microsoft.AspNetCore.Certificates.Generation
result.ResultCode = EnsureCertificateResult.Succeeded;
X509Certificate2 certificate = null;
if (certificates.Count() > 0)
if (certificates.Any())
{
result.Diagnostics.Debug("Found valid certificates present on the machine.");
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)
{
// If there are no policies we don't need to run auth
if (!policies.Any())
if (policies.Count == 0)
{
return TaskCache.True;
}

View File

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

View File

@ -159,7 +159,7 @@ namespace Microsoft.DotNet.OpenApi.Commands
var items = project.GetItems(tagName);
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.");
return;
@ -376,7 +376,7 @@ namespace Microsoft.DotNet.OpenApi.Commands
else
{
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();
if (!Path.HasExtension(lastSegment))