using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Syntriax.Engine.Core.Abstract; namespace Syntriax.Engine.Core; public static class HierarchyObjectExtensions { public static T? FindObject(this IEnumerable hierarchyObjects) where T : class { foreach (IHierarchyObject hierarchyObject in hierarchyObjects) if (hierarchyObject is T @object) return @object; return default; } public static bool TryFindObject(this IEnumerable hierarchyObjects, [NotNullWhen(returnValue: true)] out T? behaviour) where T : class { behaviour = FindObject(hierarchyObjects); return behaviour is not null; } public static void FindObjects(this IEnumerable hierarchyObjects, List behaviours) where T : class { behaviours.Clear(); foreach (IHierarchyObject hierarchyObject in hierarchyObjects) if (hierarchyObject is T @object) behaviours.Add(@object); } }