33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
|
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<T>(this IEnumerable<IHierarchyObject> hierarchyObjects) where T : class
|
||
|
{
|
||
|
foreach (IHierarchyObject hierarchyObject in hierarchyObjects)
|
||
|
if (hierarchyObject is T @object)
|
||
|
return @object;
|
||
|
|
||
|
return default;
|
||
|
}
|
||
|
|
||
|
public static bool TryFindObject<T>(this IEnumerable<IHierarchyObject> hierarchyObjects, [NotNullWhen(returnValue: true)] out T? behaviour) where T : class
|
||
|
{
|
||
|
behaviour = FindObject<T>(hierarchyObjects);
|
||
|
return behaviour is not null;
|
||
|
}
|
||
|
|
||
|
public static void FindObjects<T>(this IEnumerable<IHierarchyObject> hierarchyObjects, List<T> behaviours) where T : class
|
||
|
{
|
||
|
behaviours.Clear();
|
||
|
foreach (IHierarchyObject hierarchyObject in hierarchyObjects)
|
||
|
if (hierarchyObject is T @object)
|
||
|
behaviours.Add(@object);
|
||
|
}
|
||
|
}
|