コード例 #1
0
        /// <summary>
        /// Removes from the <see cref="PropertyObserver"/> subscriptions associated with the specified source object.
        /// </summary>
        /// <typeparam name="T">The type of the source object.</typeparam>
        /// <param name="source">The source object to unobserve.</param>
        public void Unobserve <T>(T source) where T : class, INotifyPropertyChanged
        {
            Requires.NotNull(source, nameof(source));

            CheckDisposed();

            lock (table)
            {
                if (table.TryGetValue(source, out Subscriber subscriber))
                {
                    subscriber.Dispose();

                    PropertyChangedEvent.RemoveListener(source, subscriber);

                    table.Remove(source);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Releases resources used by the <see cref="PropertyObserver"/>.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing && ValueSafe.Increment0(ref disposed))
            {
                lock (table)
                {
                    foreach (KeyValuePair <INotifyPropertyChanged, Subscriber> pair in table)
                    {
                        Subscriber subscriber = pair.Value;

                        subscriber.Dispose();

                        PropertyChangedEvent.RemoveListener(pair.Key, subscriber);
                    }

                    table.Clear();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Unsubscribes the specified delegate from the change notification of any property of the specified source object.
        /// </summary>
        /// <typeparam name="T">The type of the source object.</typeparam>
        /// <param name="source">The source object to unsubscribe from.</param>
        /// <param name="callback">The delegate to unsubscribe.</param>
        private void Unsubscribe <T>(T source, Action callback) where T : class, INotifyPropertyChanged
        {
            CheckDisposed();

            lock (table)
            {
                if (table.TryGetValue(source, out Subscriber subscriber))
                {
                    subscriber.Unsubscribe <T>(callback);

                    if (subscriber.IsEmpty)
                    {
                        subscriber.Dispose();

                        PropertyChangedEvent.RemoveListener(source, subscriber);

                        table.Remove(source);
                    }
                }
            }
        }