// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik // namespace Animancer { /// An object which wraps a object. /// https://kybernetik.com.au/animancer/api/Animancer/IWrapper /// public interface IWrapper { /************************************************************************************************************************/ /// The wrapped object. /// /// Use in case the is also an /// . /// object WrappedObject { get; } /************************************************************************************************************************/ } /// https://kybernetik.com.au/animancer/api/Animancer/AnimancerUtilities public static partial class AnimancerUtilities { /************************************************************************************************************************/ /// Returns the recursively. public static object GetWrappedObject(object wrapper) { while (wrapper is IWrapper targetWrapper) wrapper = targetWrapper.WrappedObject; return wrapper; } /// /// Returns the `wrapper` or first which is a . /// public static bool TryGetWrappedObject(object wrapper, out T wrapped) where T : class { while (true) { wrapped = wrapper as T; if (wrapped != null) return true; if (wrapper is IWrapper targetWrapper) wrapper = targetWrapper.WrappedObject; else return false; } } /************************************************************************************************************************/ } }