Use Count instead of Any() on List (#18022)
This commit is contained in:
parent
7ae6d1e379
commit
b56f84131a
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in New Issue