/// <summary> Returns info about all callbacks registered to the event handler. </summary>
        public static IEnumerable <EventFunctor> GetCallbacks(CallbackEventHandler handler)
        {
            var registry     = CallbackEventHandlerRef.GetCallbackRegistry(handler);
            var callbackList = EventCallbackRegistryRef.GetCallbackListForWriting(registry);
            var list         = EventCallbackListRef.GetList(callbackList);

            // Avoids modified collection error on unregister
            var tempList = new List <object>(list.Count);

            foreach (var item in list)
            {
                tempList.Add(item);
            }

            foreach (var functor in tempList)
            {
                var functorType = functor.GetType();

                if (!FunctorCache.infos.TryGetValue(functorType, out var info))
                {
                    info = new FunctorInfo(functorType);
                    FunctorCache.infos.Add(functorType, info);
                }

                // TODO: Should it be optimized with lambdas? It might eat up a chunk of memory in extreme cases.. Need some benchmarking.
                var callback    = (Delegate)info.m_Callback.GetValue(functor);
                var eventTypeId = (long)info.m_EventTypeId.GetValue(functor);
                var phase       = (CallbackPhase)info.phase.GetValue(functor);

                yield return(new EventFunctor()
                {
                    handler = handler,
                    callback = callback,
                    eventTypeId = eventTypeId,

                    phase = phase,
                    callbackRegistry = registry,
                });
            }
        }
        public static void UnregisterCallback(CallbackEventHandler handler, long eventTypeId, Delegate callback, TrickleDown trickle)
        {
            var registry = CallbackEventHandlerRef.GetCallbackRegistry(handler);

            EventCallbackRegistryRef.UnregisterCallback(registry, eventTypeId, callback, trickle);
        }