diff --git a/eng/Common.globalconfig b/eng/Common.globalconfig index fd878420d57..bca53055002 100644 --- a/eng/Common.globalconfig +++ b/eng/Common.globalconfig @@ -313,7 +313,7 @@ dotnet_diagnostic.CA1834.severity = suggestion dotnet_diagnostic.CA1835.severity = suggestion # Prefer IsEmpty over Count -dotnet_diagnostic.CA1836.severity = suggestion +dotnet_diagnostic.CA1836.severity = warning # Use 'Environment.ProcessId' dotnet_diagnostic.CA1837.severity = suggestion diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs index d0f17bf9dc7..af576ca2887 100644 --- a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs +++ b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs @@ -34,7 +34,7 @@ public ProjectCacheTests(ITestOutputHelper output) _env = TestEnvironment.Create(output); BuildManager.ProjectCacheItems.ShouldBeEmpty(); - _env.WithInvariant(new CustomConditionInvariant(() => BuildManager.ProjectCacheItems.Count == 0)); + _env.WithInvariant(new CustomConditionInvariant(() => BuildManager.ProjectCacheItems.IsEmpty)); } public void Dispose() diff --git a/src/Build/BackEnd/BuildManager/BuildManager.cs b/src/Build/BackEnd/BuildManager/BuildManager.cs index 2ab79c82d3c..c73477e11ec 100644 --- a/src/Build/BackEnd/BuildManager/BuildManager.cs +++ b/src/Build/BackEnd/BuildManager/BuildManager.cs @@ -1202,7 +1202,7 @@ bool ProjectCacheIsPresent() private static bool ProjectCachePresentViaVisualStudioWorkaround() { - return BuildEnvironmentHelper.Instance.RunningInVisualStudio && ProjectCacheItems.Count > 0; + return BuildEnvironmentHelper.Instance.RunningInVisualStudio && ProjectCacheItems.Any(); } // Cache requests on configuration N do not block future build submissions depending on configuration N. @@ -1261,7 +1261,7 @@ private ProjectCacheService GetProjectCacheService() private void AutomaticallyDetectAndInstantiateProjectCacheServiceForVisualStudio() { if (BuildEnvironmentHelper.Instance.RunningInVisualStudio && - ProjectCacheItems.Count > 0 && + ProjectCacheItems.Any() && _projectCacheService == null && _buildParameters.ProjectCacheDescriptor == null) { diff --git a/src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs b/src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs index 812474cec31..467bde90af6 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs @@ -238,7 +238,7 @@ public void ContinueRequestWithResources(ResourceResponse response) { ErrorUtilities.VerifyThrow(HasActiveBuildRequest, "Request not building"); ErrorUtilities.VerifyThrow(!_terminateEvent.WaitOne(0), "Request already terminated"); - ErrorUtilities.VerifyThrow(!_pendingResourceRequests.IsEmpty, "No pending resource requests"); + ErrorUtilities.VerifyThrow(_pendingResourceRequests.Any(), "No pending resource requests"); VerifyEntryInActiveOrWaitingState(); _pendingResourceRequests.Dequeue()(response); diff --git a/src/Build/BackEnd/Components/RequestBuilder/TargetBuilder.cs b/src/Build/BackEnd/Components/RequestBuilder/TargetBuilder.cs index da6d63a7d76..87604dfba2e 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/TargetBuilder.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/TargetBuilder.cs @@ -15,6 +15,7 @@ using ElementLocation = Microsoft.Build.Construction.ElementLocation; using BuildAbortedException = Microsoft.Build.Exceptions.BuildAbortedException; using TaskItem = Microsoft.Build.Execution.ProjectItemInstance.TaskItem; +using System.Linq; #nullable disable @@ -405,7 +406,7 @@ private async Task ProcessTargetStack(ITaskBuilder taskBuilder) ( !_cancellationToken.IsCancellationRequested && !stopProcessingStack && - !_targetsToBuild.IsEmpty + _targetsToBuild.Any() ) { TargetEntry currentTargetEntry = _targetsToBuild.Peek(); @@ -613,7 +614,7 @@ private void PopDependencyTargetsOnTargetFailure(TargetEntry topEntry, TargetRes // Pop down to our parent, since any other dependencies our parent had should no longer // execute. If we encounter an error target on the way down, also stop since the failure // of one error target in a set declared in OnError should not cause the others to stop running. - while ((!_targetsToBuild.IsEmpty) && (_targetsToBuild.Peek() != topEntry.ParentEntry) && !_targetsToBuild.Peek().ErrorTarget) + while ((_targetsToBuild.Any()) && (_targetsToBuild.Peek() != topEntry.ParentEntry) && !_targetsToBuild.Peek().ErrorTarget) { TargetEntry entry = _targetsToBuild.Pop(); entry.LeaveLegacyCallTargetScopes(); diff --git a/src/Build/Evaluation/LazyItemEvaluator.RemoveOperation.cs b/src/Build/Evaluation/LazyItemEvaluator.RemoveOperation.cs index 7d1e2679c7d..b742bb23311 100644 --- a/src/Build/Evaluation/LazyItemEvaluator.RemoveOperation.cs +++ b/src/Build/Evaluation/LazyItemEvaluator.RemoveOperation.cs @@ -30,7 +30,7 @@ public RemoveOperation(RemoveOperationBuilder builder, LazyItemEvaluator(builder.MatchOnMetadataOptions, _matchOnMetadata, _itemSpec); } @@ -49,7 +49,7 @@ protected override void ApplyImpl(OrderedItemDataCollection.Builder listBuilder, return; } - bool matchingOnMetadata = !_matchOnMetadata.IsEmpty; + bool matchingOnMetadata = _matchOnMetadata.Any(); if (!matchingOnMetadata) { if (ItemspecContainsASingleBareItemReference(_itemSpec, _itemElement.ItemType)) diff --git a/src/Build/Logging/ProfilerLogger.cs b/src/Build/Logging/ProfilerLogger.cs index ac43bd7f3fb..a2338b8f051 100644 --- a/src/Build/Logging/ProfilerLogger.cs +++ b/src/Build/Logging/ProfilerLogger.cs @@ -134,7 +134,7 @@ internal ProfilerResult GetAggregatedResult(bool pruneSmallItems = true) // So keeping that map here var originalLocations = new Dictionary(EvaluationLocationIdAgnosticComparer.Singleton); - while (!_profiledResults.IsEmpty) + while (_profiledResults.Any()) { ProfilerResult profiledResult; var result = _profiledResults.TryDequeue(out profiledResult); diff --git a/src/Shared/RegisteredTaskObjectCacheBase.cs b/src/Shared/RegisteredTaskObjectCacheBase.cs index db7ff5ddf4d..0feab002349 100644 --- a/src/Shared/RegisteredTaskObjectCacheBase.cs +++ b/src/Shared/RegisteredTaskObjectCacheBase.cs @@ -95,7 +95,7 @@ public object UnregisterTaskObject(object key, RegisteredTaskObjectLifetime life protected bool IsCollectionEmptyOrUncreated(RegisteredTaskObjectLifetime lifetime) { var collection = GetCollectionForLifetime(lifetime, dontCreate: true); - return (collection == null) || (collection.Count == 0); + return (collection == null) || collection.IsEmpty; } /// diff --git a/src/Tasks/GetSDKReferenceFiles.cs b/src/Tasks/GetSDKReferenceFiles.cs index 59f3cb155ae..bb9833debda 100644 --- a/src/Tasks/GetSDKReferenceFiles.cs +++ b/src/Tasks/GetSDKReferenceFiles.cs @@ -273,7 +273,7 @@ internal bool Execute(GetAssemblyName getAssemblyName, GetAssemblyRuntimeVersion GenerateOutputItems(); - if (_exceptions.Count > 0 && LogCacheFileExceptions) + if (_exceptions.Any() && LogCacheFileExceptions) { foreach (string exceptionMessage in _exceptions) {