Skip to content

Commit b56f841

Browse files
KahbaziTratcher
authored andcommitted
Use Count instead of Any() on List (#18022)
1 parent 7ae6d1e commit b56f841

File tree

14 files changed

+22
-22
lines changed

14 files changed

+22
-22
lines changed

src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ var pendingMigrations
152152
: context.Database.GetMigrations())
153153
.ToArray();
154154

155-
if (pendingModelChanges || pendingMigrations.Any())
155+
if (pendingModelChanges || pendingMigrations.Length > 0)
156156
{
157157
var page = new DatabaseErrorPage
158158
{

src/Middleware/HealthChecks/src/HealthCheckOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public IDictionary<HealthStatus, int> ResultStatusCodes
5353
private static IDictionary<HealthStatus, int> ValidateStatusCodesMapping(IDictionary<HealthStatus,int> mapping)
5454
{
5555
var missingHealthStatus = ((HealthStatus[])Enum.GetValues(typeof(HealthStatus))).Except(mapping.Keys).ToList();
56-
if (missingHealthStatus.Any())
56+
if (missingHealthStatus.Count > 0)
5757
{
5858
var missing = string.Join(", ", missingHealthStatus.Select(status => $"{nameof(HealthStatus)}.{status}"));
5959
var message =

src/Middleware/ResponseCompression/src/ResponseCompressionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public virtual ICompressionProvider GetCompressionProvider(HttpContext context)
9393
return null;
9494
}
9595

96-
if (!StringWithQualityHeaderValue.TryParseList(accept, out var encodings) || !encodings.Any())
96+
if (!StringWithQualityHeaderValue.TryParseList(accept, out var encodings) || encodings.Count == 0)
9797
{
9898
_logger.NoAcceptEncoding();
9999
return null;

src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,21 @@ public static List<TResult> Flatten<TResult>(
106106
attributeRoutingConfigurationErrors);
107107
}
108108

109-
if (attributeRoutingConfigurationErrors.Any())
109+
if (attributeRoutingConfigurationErrors.Count > 0)
110110
{
111111
var message = CreateAttributeRoutingAggregateErrorMessage(attributeRoutingConfigurationErrors.Values);
112112

113113
throw new InvalidOperationException(message);
114114
}
115115

116116
var namedRoutedErrors = ValidateNamedAttributeRoutedActions(actionsByRouteName);
117-
if (namedRoutedErrors.Any())
117+
if (namedRoutedErrors.Count > 0)
118118
{
119119
var message = CreateAttributeRoutingAggregateErrorMessage(namedRoutedErrors);
120120
throw new InvalidOperationException(message);
121121
}
122122

123-
if (routeTemplateErrors.Any())
123+
if (routeTemplateErrors.Count > 0)
124124
{
125125
var message = CreateAttributeRoutingAggregateErrorMessage(routeTemplateErrors);
126126
throw new InvalidOperationException(message);

src/Mvc/Mvc.Core/src/Infrastructure/FileResultExecutorBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private static PreconditionState GetEtagMatchState(
260260
PreconditionState matchFoundState,
261261
PreconditionState matchNotFoundState)
262262
{
263-
if (etagHeader != null && etagHeader.Any())
263+
if (etagHeader?.Count > 0)
264264
{
265265
var state = matchNotFoundState;
266266
foreach (var entityTag in etagHeader)

src/Mvc/Mvc.TagHelpers/src/TagHelperOutputExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static void RemoveClass(
277277

278278
listOfClasses.RemoveAll(x => x.Equals(encodedClassValue));
279279

280-
if (listOfClasses.Any())
280+
if (listOfClasses.Count > 0)
281281
{
282282
var joinedClasses = new HtmlString(string.Join(" ", listOfClasses));
283283
tagHelperOutput.Attributes.SetAttribute(classAttribute.Name, joinedClasses);
@@ -428,4 +428,4 @@ public void WriteTo(TextWriter writer, HtmlEncoder encoder)
428428
}
429429
}
430430
}
431-
}
431+
}

src/Security/Authorization/Core/src/AuthorizationPolicy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public AuthorizationPolicy(IEnumerable<IAuthorizationRequirement> requirements,
3737
throw new ArgumentNullException(nameof(authenticationSchemes));
3838
}
3939

40-
if (requirements.Count() == 0)
40+
if (!requirements.Any())
4141
{
4242
throw new InvalidOperationException(Resources.Exception_AuthorizationPolicyEmpty);
4343
}
@@ -150,15 +150,15 @@ public static async Task<AuthorizationPolicy> CombineAsync(IAuthorizationPolicyP
150150
}
151151

152152
var rolesSplit = authorizeDatum.Roles?.Split(',');
153-
if (rolesSplit != null && rolesSplit.Any())
153+
if (rolesSplit?.Length > 0)
154154
{
155155
var trimmedRolesSplit = rolesSplit.Where(r => !string.IsNullOrWhiteSpace(r)).Select(r => r.Trim());
156156
policyBuilder.RequireRole(trimmedRolesSplit);
157157
useDefaultPolicy = false;
158158
}
159159

160160
var authTypesSplit = authorizeDatum.AuthenticationSchemes?.Split(',');
161-
if (authTypesSplit != null && authTypesSplit.Any())
161+
if (authTypesSplit?.Length > 0)
162162
{
163163
foreach (var authType in authTypesSplit)
164164
{

src/Security/Authorization/Core/src/RolesAuthorizationRequirement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RolesAuthorizationRequirement(IEnumerable<string> allowedRoles)
2525
throw new ArgumentNullException(nameof(allowedRoles));
2626
}
2727

28-
if (allowedRoles.Count() == 0)
28+
if (!allowedRoles.Any())
2929
{
3030
throw new InvalidOperationException(Resources.Exception_RoleRequirementEmpty);
3131
}

src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task Invoke(HttpContext context)
6868

6969
if (authorizeResult.Challenged)
7070
{
71-
if (policy.AuthenticationSchemes.Any())
71+
if (policy.AuthenticationSchemes.Count > 0)
7272
{
7373
foreach (var scheme in policy.AuthenticationSchemes)
7474
{
@@ -84,7 +84,7 @@ public async Task Invoke(HttpContext context)
8484
}
8585
else if (authorizeResult.Forbidden)
8686
{
87-
if (policy.AuthenticationSchemes.Any())
87+
if (policy.AuthenticationSchemes.Count > 0)
8888
{
8989
foreach (var scheme in policy.AuthenticationSchemes)
9090
{

src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected override void Dispose(bool disposing)
119119
MemoryPoolThrowHelper.ThrowInvalidOperationException_DisposingPoolWithActiveBlocks(_totalBlocks - _blocks.Count, _totalBlocks, _blocks.ToArray());
120120
}
121121

122-
if (_blockAccessExceptions.Any())
122+
if (_blockAccessExceptions.Count > 0)
123123
{
124124
throw CreateAccessExceptions();
125125
}
@@ -136,7 +136,7 @@ protected override void Dispose(bool disposing)
136136

137137
private void SetAllBlocksReturned()
138138
{
139-
if (_blockAccessExceptions.Any())
139+
if (_blockAccessExceptions.Count > 0)
140140
{
141141
_allBlocksReturned.SetException(CreateAccessExceptions());
142142
}

src/Shared/CertificateGeneration/CertificateManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ public DetailedEnsureCertificateResult EnsureValidCertificateExists(
752752
result.ResultCode = EnsureCertificateResult.Succeeded;
753753

754754
X509Certificate2 certificate = null;
755-
if (certificates.Count() > 0)
755+
if (certificates.Any())
756756
{
757757
result.Diagnostics.Debug("Found valid certificates present on the machine.");
758758
result.Diagnostics.Debug(result.Diagnostics.DescribeCertificates(certificates));

src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ private void InitializeHub(THub hub, HubConnectionContext connection)
489489
private Task<bool> IsHubMethodAuthorized(IServiceProvider provider, HubConnectionContext hubConnectionContext, IList<IAuthorizeData> policies, string hubMethodName, object[] hubMethodArguments)
490490
{
491491
// If there are no policies we don't need to run auth
492-
if (!policies.Any())
492+
if (policies.Count == 0)
493493
{
494494
return TaskCache.True;
495495
}

src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private static void BuildMethod(TypeBuilder type, MethodInfo interfaceMethodInfo
131131
var genericTypeNames =
132132
paramTypes.Where(p => p.IsGenericParameter).Select(p => p.Name).Distinct().ToArray();
133133

134-
if (genericTypeNames.Any())
134+
if (genericTypeNames.Length > 0)
135135
{
136136
methodBuilder.DefineGenericParameters(genericTypeNames);
137137
}

src/Tools/Microsoft.dotnet-openapi/src/Commands/BaseCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ internal async Task AddOpenAPIReference(
159159
var items = project.GetItems(tagName);
160160
var fileItems = items.Where(i => string.Equals(GetFullPath(i.EvaluatedInclude), GetFullPath(sourceFile), StringComparison.Ordinal));
161161

162-
if (fileItems.Count() > 0)
162+
if (fileItems.Any())
163163
{
164164
Warning.Write($"One or more references to {sourceFile} already exist in '{project.FullPath}'. Duplicate references could lead to unexpected behavior.");
165165
return;
@@ -376,7 +376,7 @@ private string GetFileNameFromResponse(IHttpResponseMessageWrapper response, str
376376
else
377377
{
378378
var uri = new Uri(url);
379-
if (uri.Segments.Count() > 0 && uri.Segments.Last() != "/")
379+
if (uri.Segments.Any() && uri.Segments.Last() != "/")
380380
{
381381
var lastSegment = uri.Segments.Last();
382382
if (!Path.HasExtension(lastSegment))

0 commit comments

Comments
 (0)