コード例 #1
0
        /// <summary>
        /// Searches the subscriber for event handlers it implements, and removes any that can be found.
        /// </summary>
        /// <param name="subscriber">The subscriber to remove the event handlers of.</param>
        /// <returns><c>true</c> if at least one event handler was removed; <c>false</c> if none could be found.</returns>
        public bool RemoveAll(object subscriber)
        {
            if (subscriber.NullReference())
            {
                throw Exc.Null(nameof(subscriber));
            }

            var subscriberTypeInfo = EventSubscriberTypeInfo.AddOrGet(subscriber.GetType());

            return(subscriberTypeInfo.RemoveAll(this, subscriber));
        }
コード例 #2
0
        /// <summary>
        /// Searches the subscriber for event handlers it implements,
        /// and adds those that were not yet registered.
        /// </summary>
        /// <param name="subscriber">The subscriber to add the event handlers of.</param>
        /// <param name="weakRef"><c>true</c> to store weak references; <c>false</c> to store strong references.</param>
        /// <returns><c>true</c> if at least one event handler was added; otherwise, <c>false</c>.</returns>
        public bool AddAll(object subscriber, bool weakRef = true)
        {
            if (subscriber.NullReference())
            {
                throw Exc.Null(nameof(subscriber));
            }

            var subscriberTypeInfo = EventSubscriberTypeInfo.AddOrGet(subscriber.GetType());

            return(subscriberTypeInfo.AddAll(this, subscriber, weakRef));
        }
コード例 #3
0
        internal static EventSubscriberTypeInfo AddOrGet(Type subscriberType)
        {
            if (subscriberType.NullReference())
            {
                throw Exc.Null(nameof(subscriberType));
            }

            lock ( syncLock )
            {
                if (!subscriberInfos.TryGetValue(subscriberType, out var info))
                {
                    info = new EventSubscriberTypeInfo(subscriberType);
                    subscriberInfos.Add(subscriberType, info);
                }
                return(info);
            }
        }