public static void Unsubscribe <TOpenEventHandler, TStrongHandler>(
            object?lifetimeObject,
            DelegateCollectionBase <TOpenEventHandler, TStrongHandler>?handlers,
            Delegate handler)
            where TOpenEventHandler : Delegate
            where TStrongHandler : struct
        {
            if (handler is null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            if (handlers is null)
            {
                return;
            }

            var invocationList = handler.GetInvocationList();

            lock (handlers)
            {
                handlers.Remove(lifetimeObject, invocationList);
                handlers.CollectDeleted();
            }
        }
        public static IEnumerable <TStrongHandler> GetValidHandlers <TOpenEventHandler, TStrongHandler>(
            DelegateCollectionBase <TOpenEventHandler, TStrongHandler>?handlers)
            where TOpenEventHandler : Delegate
            where TStrongHandler : struct
        {
            if (handlers is null)
            {
                return(Enumerable.Empty <TStrongHandler>());
            }

            List <TStrongHandler> validHandlers;

            lock (handlers)
            {
                validHandlers = new List <TStrongHandler>(handlers.Count);
                for (int i = 0; i < handlers.Count; i++)
                {
                    var weakHandler = handlers[i];
                    if (weakHandler != null)
                    {
                        if (weakHandler.TryGetStrongHandler() is TStrongHandler handler)
                        {
                            validHandlers.Add(handler);
                        }
                        else
                        {
                            handlers.Invalidate(i);
                        }
                    }
                }

                handlers.CollectDeleted();
            }

            return(validHandlers);
        }