From b56f84131af2e1ece61241a016e191f5f2fe3fc0 Mon Sep 17 00:00:00 2001 From: Kahbazi Date: Thu, 2 Jan 2020 19:25:29 +0330 Subject: [PATCH] Use Count instead of Any() on List (#18022) --- .../src/DatabaseErrorPageMiddleware.cs | 2 +- src/Middleware/HealthChecks/src/HealthCheckOptions.cs | 2 +- .../ResponseCompression/src/ResponseCompressionProvider.cs | 2 +- .../src/ApplicationModels/ApplicationModelFactory.cs | 6 +++--- .../Mvc.Core/src/Infrastructure/FileResultExecutorBase.cs | 2 +- src/Mvc/Mvc.TagHelpers/src/TagHelperOutputExtensions.cs | 4 ++-- src/Security/Authorization/Core/src/AuthorizationPolicy.cs | 6 +++--- .../Authorization/Core/src/RolesAuthorizationRequirement.cs | 2 +- .../Authorization/Policy/src/AuthorizationMiddleware.cs | 4 ++-- src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs | 4 ++-- src/Shared/CertificateGeneration/CertificateManager.cs | 2 +- .../server/Core/src/Internal/DefaultHubDispatcher.cs | 2 +- src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs | 2 +- .../Microsoft.dotnet-openapi/src/Commands/BaseCommand.cs | 4 ++-- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs b/src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs index 26db9dcb22..ac2e913c24 100644 --- a/src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs +++ b/src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs @@ -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 { diff --git a/src/Middleware/HealthChecks/src/HealthCheckOptions.cs b/src/Middleware/HealthChecks/src/HealthCheckOptions.cs index c5ef255662..8d7ea07098 100644 --- a/src/Middleware/HealthChecks/src/HealthCheckOptions.cs +++ b/src/Middleware/HealthChecks/src/HealthCheckOptions.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Diagnostics.HealthChecks private static IDictionary ValidateStatusCodesMapping(IDictionary 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 = diff --git a/src/Middleware/ResponseCompression/src/ResponseCompressionProvider.cs b/src/Middleware/ResponseCompression/src/ResponseCompressionProvider.cs index ad29ab7b2c..8592f25260 100644 --- a/src/Middleware/ResponseCompression/src/ResponseCompressionProvider.cs +++ b/src/Middleware/ResponseCompression/src/ResponseCompressionProvider.cs @@ -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; diff --git a/src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs b/src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs index b86e5465d9..88f8ce93f4 100644 --- a/src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs +++ b/src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs @@ -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); diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/FileResultExecutorBase.cs b/src/Mvc/Mvc.Core/src/Infrastructure/FileResultExecutorBase.cs index 48ad5f3ad9..cc6acf5ad3 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/FileResultExecutorBase.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/FileResultExecutorBase.cs @@ -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) diff --git a/src/Mvc/Mvc.TagHelpers/src/TagHelperOutputExtensions.cs b/src/Mvc/Mvc.TagHelpers/src/TagHelperOutputExtensions.cs index eb34746701..09d73843f5 100644 --- a/src/Mvc/Mvc.TagHelpers/src/TagHelperOutputExtensions.cs +++ b/src/Mvc/Mvc.TagHelpers/src/TagHelperOutputExtensions.cs @@ -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 } } } -} \ No newline at end of file +} diff --git a/src/Security/Authorization/Core/src/AuthorizationPolicy.cs b/src/Security/Authorization/Core/src/AuthorizationPolicy.cs index f1833da954..b7c52722fa 100644 --- a/src/Security/Authorization/Core/src/AuthorizationPolicy.cs +++ b/src/Security/Authorization/Core/src/AuthorizationPolicy.cs @@ -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) { diff --git a/src/Security/Authorization/Core/src/RolesAuthorizationRequirement.cs b/src/Security/Authorization/Core/src/RolesAuthorizationRequirement.cs index c3a11cdc47..e5a2251a14 100644 --- a/src/Security/Authorization/Core/src/RolesAuthorizationRequirement.cs +++ b/src/Security/Authorization/Core/src/RolesAuthorizationRequirement.cs @@ -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); } diff --git a/src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs b/src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs index 686374d829..af115e9daa 100644 --- a/src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs +++ b/src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs @@ -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) { diff --git a/src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs b/src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs index 4cbea8a866..fe3e2eb51d 100644 --- a/src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs +++ b/src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs @@ -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()); } diff --git a/src/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index 09824fb127..c40c9e6413 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -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)); diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs index ff59c581bb..74d7fe27ca 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs @@ -489,7 +489,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal private Task IsHubMethodAuthorized(IServiceProvider provider, HubConnectionContext hubConnectionContext, IList 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; } diff --git a/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs b/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs index da171d9a47..b0343577cb 100644 --- a/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs +++ b/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs @@ -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); } diff --git a/src/Tools/Microsoft.dotnet-openapi/src/Commands/BaseCommand.cs b/src/Tools/Microsoft.dotnet-openapi/src/Commands/BaseCommand.cs index ac6e8bcdc8..88cc458a1f 100644 --- a/src/Tools/Microsoft.dotnet-openapi/src/Commands/BaseCommand.cs +++ b/src/Tools/Microsoft.dotnet-openapi/src/Commands/BaseCommand.cs @@ -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))