Fix CA1860: Avoid using 'Enumerable.Any()' extension method

This commit is contained in:
Haselnussbomber 2025-10-24 02:35:44 +02:00
parent fe37da1b94
commit d060db3ca4
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
10 changed files with 22 additions and 22 deletions

View file

@ -151,7 +151,7 @@ internal class GameInventory : IInternalDisposableService
bool isNew;
lock (this.subscribersPendingChange)
{
isNew = this.subscribersPendingChange.Any() && !this.subscribers.Any();
isNew = this.subscribersPendingChange.Count != 0 && this.subscribers.Count == 0;
this.subscribers.Clear();
this.subscribers.AddRange(this.subscribersPendingChange);
this.subscribersChanged = false;

View file

@ -83,7 +83,7 @@ public sealed class SystemFontFamilyId : IFontFamilyId
else if (candidates.Any(x => x.Style == (int)DWRITE_FONT_STYLE.DWRITE_FONT_STYLE_NORMAL))
candidates.RemoveAll(x => x.Style != (int)DWRITE_FONT_STYLE.DWRITE_FONT_STYLE_NORMAL);
if (!candidates.Any())
if (candidates.Count == 0)
return 0;
for (var i = 0; i < this.Fonts.Count; i++)

View file

@ -400,7 +400,7 @@ internal unsafe partial class Dx11Renderer : IImGuiRenderer
{
ObjectDisposedException.ThrowIf(this.device.IsEmpty(), this);
if (this.fontTextures.Any())
if (this.fontTextures.Count != 0)
return;
var io = ImGui.GetIO();

View file

@ -357,7 +357,7 @@ internal class PluginImageCache : IInternalDisposableService
try
{
token.ThrowIfCancellationRequested();
if (!pendingFuncs.Any())
if (pendingFuncs.Count == 0)
{
if (!this.downloadQueue.TryTake(out var taskTuple, -1, token))
return;
@ -373,7 +373,7 @@ internal class PluginImageCache : IInternalDisposableService
pendingFuncs = pendingFuncs.OrderBy(x => x.Item1).ToList();
var item1 = pendingFuncs.Last().Item1;
while (pendingFuncs.Any() && pendingFuncs.Last().Item1 == item1)
while (pendingFuncs.Count != 0 && pendingFuncs.Last().Item1 == item1)
{
token.ThrowIfCancellationRequested();
while (runningTasks.Count >= concurrency)

View file

@ -186,7 +186,7 @@ internal class PluginStatWindow : Window
ImGui.SameLine();
ImGuiComponents.TextWithLabel("Total Average", $"{totalAverage:F4}ms", "All average update times added together");
ImGui.SameLine();
ImGuiComponents.TextWithLabel("Collective Average", $"{(statsHistory.Any() ? totalAverage / statsHistory.Length : 0):F4}ms", "Average of all average update times");
ImGuiComponents.TextWithLabel("Collective Average", $"{(statsHistory.Length != 0 ? totalAverage / statsHistory.Length : 0):F4}ms", "Average of all average update times");
ImGui.InputTextWithHint(
"###PluginStatWindow_FrameworkSearch"u8,
@ -230,7 +230,7 @@ internal class PluginStatWindow : Window
foreach (var handlerHistory in statsHistory)
{
if (!handlerHistory.Value.Any())
if (handlerHistory.Value.Count == 0)
{
continue;
}

View file

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@ -42,7 +42,7 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
{
lock (this.entries)
{
if (!this.entries.Any())
if (this.entries.Count == 0)
return Array.Empty<TitleScreenMenuEntry>();
return this.entriesView ??= this.entries.OrderByDescending(x => x.IsInternal).ToArray();
@ -59,7 +59,7 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
{
lock (this.entries)
{
if (!this.entries.Any())
if (this.entries.Count == 0)
return Array.Empty<TitleScreenMenuEntry>();
return this.entriesView ??= this.entries.OrderByDescending(x => x.IsInternal).ToArray();
@ -81,7 +81,7 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
lock (this.entries)
{
var entriesOfAssembly = this.entries.Where(x => x.CallingAssembly == Assembly.GetCallingAssembly()).ToList();
var priority = entriesOfAssembly.Any()
var priority = entriesOfAssembly.Count != 0
? unchecked(entriesOfAssembly.Select(x => x.Priority).Max() + 1)
: 0;
entry = new(Assembly.GetCallingAssembly(), priority, text, texture, onTriggered);
@ -191,7 +191,7 @@ internal class TitleScreenMenu : IServiceType, ITitleScreenMenu
lock (this.entries)
{
var entriesOfAssembly = this.entries.Where(x => x.CallingAssembly == null).ToList();
var priority = entriesOfAssembly.Any()
var priority = entriesOfAssembly.Count != 0
? unchecked(entriesOfAssembly.Select(x => x.Priority).Max() + 1)
: 0;
entry = new(null, priority, text, texture, onTriggered, showConditionKeys)

View file

@ -376,7 +376,7 @@ internal class AutoUpdateManager : IServiceType
}
}
private void NotifyUpdatesAreAvailable(ICollection<AvailablePluginUpdate> updatablePlugins)
private void NotifyUpdatesAreAvailable(List<AvailablePluginUpdate> updatablePlugins)
{
if (updatablePlugins.Count == 0)
return;

View file

@ -24,7 +24,7 @@ internal class ManagedLoadContext : AssemblyLoadContext
private readonly IReadOnlyDictionary<string, ManagedLibrary> managedAssemblies;
private readonly IReadOnlyDictionary<string, NativeLibrary> nativeLibraries;
private readonly IReadOnlyCollection<string> privateAssemblies;
private readonly ICollection<string> defaultAssemblies;
private readonly List<string> defaultAssemblies;
private readonly IReadOnlyCollection<string> additionalProbingPaths;
private readonly bool preferDefaultLoadContext;
private readonly string[] resourceRoots;

View file

@ -317,7 +317,7 @@ internal static class ServiceManager
servicesToLoad.UnionWith(earlyLoadingServices);
servicesToLoad.UnionWith(blockingEarlyLoadingServices);
while (servicesToLoad.Any())
while (servicesToLoad.Count != 0)
{
foreach (var serviceType in servicesToLoad)
{
@ -383,23 +383,23 @@ internal static class ServiceManager
#endif
}
if (!tasks.Any())
if (tasks.Count == 0)
{
// No more services we can start loading for now.
// Either we're waiting for provided services, or there's a dependency cycle.
providedServices.RemoveWhere(x => getAsyncTaskMap[x].IsCompleted);
if (providedServices.Any())
if (providedServices.Count != 0)
await Task.WhenAny(providedServices.Select(x => getAsyncTaskMap[x]));
else
throw new InvalidOperationException("Unresolvable dependency cycle detected");
continue;
}
if (servicesToLoad.Any())
if (servicesToLoad.Count != 0)
{
await Task.WhenAny(tasks);
var faultedTasks = tasks.Where(x => x.IsFaulted).Select(x => (Exception)x.Exception!).ToArray();
if (faultedTasks.Any())
if (faultedTasks.Length != 0)
throw new AggregateException(faultedTasks);
}
else
@ -426,7 +426,7 @@ internal static class ServiceManager
await loadingDialog.HideAndJoin();
while (tasks.Any())
while (tasks.Count != 0)
{
await Task.WhenAny(tasks);
tasks.RemoveAll(x => x.IsCompleted);

View file

@ -206,7 +206,7 @@ internal static class Service<T> where T : IServiceType
is not ServiceManager.ServiceKind.BlockingEarlyLoadedService
and not ServiceManager.ServiceKind.ProvidedService)
.ToArray();
if (offenders.Any())
if (offenders.Length != 0)
{
const string bels = nameof(ServiceManager.BlockingEarlyLoadedServiceAttribute);
const string ps = nameof(ServiceManager.ProvidedServiceAttribute);
@ -351,7 +351,7 @@ internal static class Service<T> where T : IServiceType
BindingFlags.CreateInstance | BindingFlags.OptionalParamBinding;
return typeof(T)
.GetConstructors(ctorBindingFlags)
.SingleOrDefault(x => x.GetCustomAttributes(typeof(ServiceManager.ServiceConstructor), true).Any());
.SingleOrDefault(x => x.GetCustomAttributes(typeof(ServiceManager.ServiceConstructor), true).Length != 0);
}
private static async Task<T> ConstructObject(IReadOnlyCollection<object> additionalProvidedTypedObjects)