From 2df41e18818e314ebfa21e578500d5e3161cf850 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sun, 25 May 2025 13:28:27 +0300 Subject: [PATCH] docs: added universe and universe object extension documentation comments --- Engine.Core/Extensions/UniverseExtensions.cs | 15 +++++ .../Extensions/UniverseObjectExtensions.cs | 58 +++++++++++++++++-- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/Engine.Core/Extensions/UniverseExtensions.cs b/Engine.Core/Extensions/UniverseExtensions.cs index d54c811..c490e4b 100644 --- a/Engine.Core/Extensions/UniverseExtensions.cs +++ b/Engine.Core/Extensions/UniverseExtensions.cs @@ -7,12 +7,27 @@ public static class UniverseExtensions public static IUniverseObject InstantiateUniverseObject(this IUniverse universe, params object?[]? args) => universe.InstantiateUniverseObject(args); + /// + /// Searches through alls to find the specified instance of the type. + /// + /// Type to be searched through the . + /// The specified type if found; otherwise, throws . public static T GetRequiredUniverseObject(this IUniverse universe) where T : class => universe.GetUniverseObject() ?? throw new UniverseObjectNotFoundException($"{universe.GetType().FullName}({universe.Id}) does not contain any {nameof(IUniverseObject)} object of type {typeof(T).FullName}"); + /// + /// Searches through alls to find the specified instance of the type. + /// + /// Type to be searched through the . + /// The specified type if found; otherwise, throws . public static T FindRequiredBehaviour(this IUniverse universe) where T : class => universe.FindBehaviour() ?? throw new BehaviourNotFoundException($"{universe.GetType().FullName}({universe.Id}) does not contain any {nameof(IUniverseObject)} with {nameof(IBehaviour)} of type {typeof(T).FullName}"); + /// + /// Searches through all s and s to find the specified instance of the type. + /// + /// Type to be searched through the . + /// The specified type if found; otherwise, throws . public static T FindRequired(this IUniverse universe) where T : class => universe.Find() ?? throw new NotFoundException($"{universe.GetType().FullName}({universe.Id}) does not contain any {nameof(IUniverseObject)} or {nameof(IBehaviour)} of type {typeof(T).FullName}"); } diff --git a/Engine.Core/Extensions/UniverseObjectExtensions.cs b/Engine.Core/Extensions/UniverseObjectExtensions.cs index e836195..47b8860 100644 --- a/Engine.Core/Extensions/UniverseObjectExtensions.cs +++ b/Engine.Core/Extensions/UniverseObjectExtensions.cs @@ -17,7 +17,12 @@ public static class UniverseObjectExtensions } #region Universe Object Search - + /// + /// Gets a of the specified type. + /// + /// The type of to get. + /// The s to search. + /// The first found of the specified type; otherwise, null. public static T? GetUniverseObject(this IEnumerable universeObjects) where T : class { foreach (IUniverseObject universeObject in universeObjects) @@ -27,12 +32,24 @@ public static class UniverseObjectExtensions return default; } + /// + /// Tries to get a of the specified type. + /// + /// The type of to get. + /// The s to search. + /// if a of the specified type was found in the universe objects; otherwise, . public static bool TryGetUniverseObject(this IEnumerable universeObjects, [NotNullWhen(returnValue: true)] out T? universeObject) where T : class { universeObject = GetUniverseObject(universeObjects); return universeObject is not null; } + /// + /// Searches through the provided s to collect a list of s of the specified type. + /// + /// The type of to get. + /// The to search. + /// The found s of the specified types public static void GetUniverseObjects(this IEnumerable universeObjects, IList foundUniverseObjects) where T : class { foundUniverseObjects.Clear(); @@ -133,6 +150,11 @@ public static class UniverseObjectExtensions #endregion #region Behaviour Search + /// + /// Finds a of the specified type in the provided s. + /// + /// The type of to find. + /// The first found of the specified type; otherwise, null. public static T? FindBehaviour(this IEnumerable universeObjects) where T : class { foreach (IUniverseObject universeObject in universeObjects) @@ -142,12 +164,23 @@ public static class UniverseObjectExtensions return default; } + /// + /// Tries to find a of the specified type in the provided s. + /// + /// The type of to find. + /// When this method returns, contains the of the specified type, if found; otherwise, null. + /// if a of the specified type was found in the provided s; otherwise, . public static bool TryFindBehaviour(this IEnumerable universeObjects, [NotNullWhen(returnValue: true)] out T? behaviour) where T : class { behaviour = FindBehaviour(universeObjects); return behaviour is not null; } + /// + /// Searches through the provided s to collect a list of s of the specified type. + /// + /// The type of to get. + /// The s to search. public static void FindBehaviours(this IEnumerable universeObjects, IList behaviours) where T : class { behaviours.Clear(); @@ -163,6 +196,11 @@ public static class UniverseObjectExtensions #endregion #region General Search + /// + /// Finds an object of the specified type in the provided s and their s. + /// + /// The type of to find. + /// The first found instance of the specified type; otherwise, null. public static T? Find(this IEnumerable universeObjects) where T : class { if (universeObjects.GetUniverseObject() is T foundUniverseObject) @@ -174,22 +212,34 @@ public static class UniverseObjectExtensions return null; } + /// + /// Tries to find an object of the specified type in the provided s and their s. + /// + /// The type of to find. + /// When this method returns, contains the of the specified type, if found; otherwise, null. + /// if an object of the specified type was found in the provided s; otherwise, . public static bool TryFind(this IEnumerable universeObjects, [NotNullWhen(returnValue: true)] out T? behaviour) where T : class { behaviour = Find(universeObjects); return behaviour is not null; } - public static void Find(this IEnumerable universeObjects, IList behaviours) where T : class + /// + /// Searches through the provided s and their s to collect a list of the specified type. + /// + /// The type of to get. + /// List of objects found wit the specified type. + /// The s to search. + public static void Find(this IEnumerable universeObjects, IList instances) where T : class { - behaviours.Clear(); + instances.Clear(); List cache = []; foreach (IUniverseObject universeObject in universeObjects) { universeObject.Find(cache); foreach (T behaviour in cache) - behaviours.Add(behaviour); + instances.Add(behaviour); } } #endregion