From 052f87108f68b33e94e4a4868ff9399d9748a04a Mon Sep 17 00:00:00 2001 From: Jevon Date: Sat, 14 May 2022 09:00:15 +0100 Subject: [PATCH] Swap use of deprecated `FindAll` method to `Where`/`ToArray` #612 - Updating Windsor to support Castle.Core@5.0.0 and modern TFMs --- src/Castle.Windsor/Core/Internal/ReflectionUtil.cs | 2 +- .../PotentiallyMisconfiguredComponentsDiagnostic.cs | 5 +++-- .../Diagnostics/UsingContainerAsServiceLocatorDiagnostic.cs | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Castle.Windsor/Core/Internal/ReflectionUtil.cs b/src/Castle.Windsor/Core/Internal/ReflectionUtil.cs index ae13fea3de..1372e7922a 100644 --- a/src/Castle.Windsor/Core/Internal/ReflectionUtil.cs +++ b/src/Castle.Windsor/Core/Internal/ReflectionUtil.cs @@ -159,7 +159,7 @@ public static Type[] GetAvailableTypes(this Assembly assembly, bool includeNonEx } catch (ReflectionTypeLoadException e) { - return e.Types.FindAll(t => t != null); + return e.Types.Where(t => t != null).ToArray(); // NOTE: perhaps we should not ignore the exceptions here, and log them? } } diff --git a/src/Castle.Windsor/Windsor/Diagnostics/PotentiallyMisconfiguredComponentsDiagnostic.cs b/src/Castle.Windsor/Windsor/Diagnostics/PotentiallyMisconfiguredComponentsDiagnostic.cs index 2688f2f4ef..5305785bd9 100644 --- a/src/Castle.Windsor/Windsor/Diagnostics/PotentiallyMisconfiguredComponentsDiagnostic.cs +++ b/src/Castle.Windsor/Windsor/Diagnostics/PotentiallyMisconfiguredComponentsDiagnostic.cs @@ -14,7 +14,8 @@ namespace Castle.Windsor.Diagnostics { - using Castle.Core.Internal; + using System.Linq; + using Castle.MicroKernel; public class PotentiallyMisconfiguredComponentsDiagnostic : IPotentiallyMisconfiguredComponentsDiagnostic @@ -29,7 +30,7 @@ public PotentiallyMisconfiguredComponentsDiagnostic(IKernel kernel) public IHandler[] Inspect() { var allHandlers = kernel.GetAssignableHandlers(typeof(object)); - var waitingHandlers = allHandlers.FindAll(IsWaitingForDependencies); + var waitingHandlers = allHandlers.Where(IsWaitingForDependencies).ToArray(); return waitingHandlers; } diff --git a/src/Castle.Windsor/Windsor/Diagnostics/UsingContainerAsServiceLocatorDiagnostic.cs b/src/Castle.Windsor/Windsor/Diagnostics/UsingContainerAsServiceLocatorDiagnostic.cs index b510f435ef..720731e546 100644 --- a/src/Castle.Windsor/Windsor/Diagnostics/UsingContainerAsServiceLocatorDiagnostic.cs +++ b/src/Castle.Windsor/Windsor/Diagnostics/UsingContainerAsServiceLocatorDiagnostic.cs @@ -51,8 +51,10 @@ public UsingContainerAsServiceLocatorDiagnostic(IKernel kernel) public IHandler[] Inspect() { var allHandlers = kernel.GetAssignableHandlers(typeof(object)); - var handlersWithContainerDependency = allHandlers.FindAll(HasDependencyOnTheContainer); - return handlersWithContainerDependency.FindAll(h => ExceptionsToTheRule.Any(e => e(h)) == false); + var handlersWithContainerDependency = allHandlers.Where(HasDependencyOnTheContainer); + return handlersWithContainerDependency + .Where(h => ExceptionsToTheRule.Any(e => e(h)) == false) + .ToArray(); } private bool HasDependencyOnTheContainer(IHandler handler)