/// <summary> /// Adds a subscriber to the server's notification list. /// </summary> /// <param name="target">The target object for which the subscriber is requesting notifications.</param> /// <param name="subscriber">The subscriber that wishes to receive notifications for the specified target.</param> public void Subscribe(DependencyObject target, IDependencyPropertyChangeNotificationSubscriber subscriber) { lock (subscriptions) { PooledLinkedList <IDependencyPropertyChangeNotificationSubscriber> subscribers; if (!subscriptions.TryGetValue(target, out subscribers)) { lock (subscriberListPool) { subscribers = subscriberListPool.Retrieve(); } subscriptions[target] = subscribers; } subscribers.AddLast(subscriber); } }
/// <summary> /// Adds a subscriber to the server's notification list. /// </summary> /// <param name="target">The target object for which the subscriber is requesting notifications.</param> /// <param name="subscriber">The subscriber that wishes to receive notifications for the specified target.</param> public void Subscribe(DependencyObject target, IDependencyPropertyChangeNotificationSubscriber subscriber) { lock (subscriptions) { PooledLinkedList<IDependencyPropertyChangeNotificationSubscriber> subscribers; if (!subscriptions.TryGetValue(target, out subscribers)) { lock (subscriberListPool) { subscribers = subscriberListPool.Retrieve(); } subscriptions[target] = subscribers; } subscribers.AddLast(subscriber); } }
/// <summary> /// Removes a subscriber from the server's notification list. /// </summary> /// <param name="target">The target object for which the subscriber was requesting notifications.</param> /// <param name="subscriber">The subscriber that wishes to stop receiving notifications for the specified target.</param> public void Unsubscribe(DependencyObject target, IDependencyPropertyChangeNotificationSubscriber subscriber) { lock (subscriptions) { PooledLinkedList<IDependencyPropertyChangeNotificationSubscriber> subscribers; if (!subscriptions.TryGetValue(target, out subscribers)) return; subscribers.Remove(subscriber); if (subscribers.Count == 0) { subscriptions.Remove(target); lock (subscriberListPool) { subscriberListPool.Release(subscribers); } } } }
/// <summary> /// Removes a subscriber from the server's notification list. /// </summary> /// <param name="target">The target object for which the subscriber was requesting notifications.</param> /// <param name="subscriber">The subscriber that wishes to stop receiving notifications for the specified target.</param> public void Unsubscribe(DependencyObject target, IDependencyPropertyChangeNotificationSubscriber subscriber) { lock (subscriptions) { PooledLinkedList <IDependencyPropertyChangeNotificationSubscriber> subscribers; if (!subscriptions.TryGetValue(target, out subscribers)) { return; } subscribers.Remove(subscriber); if (subscribers.Count == 0) { subscriptions.Remove(target); lock (subscriberListPool) { subscriberListPool.Release(subscribers); } } } }
/// <summary> /// Unregisters the specified subscriber from receiving change notifications for the specified dependency property. /// </summary> /// <param name="dobj">The dependency object to monitor for changes.</param> /// <param name="dprop">The dependency property for which to stop receiving change notifications.</param> /// <param name="subscriber">The subscriber that wishes to stop receiving change notifications for the specified dependency property.</param> internal static void UnregisterChangeNotification(DependencyObject dobj, DependencyProperty dprop, IDependencyPropertyChangeNotificationSubscriber subscriber) { Contract.Require(dobj, "dobj"); Contract.Require(dprop, "dprop"); Contract.Require(subscriber, "subscriber"); dprop.changeNotificationServer.Unsubscribe(dobj, subscriber); }
/// <summary> /// Unregisters the specified subscriber from receiving change notifications for the specified dependency property. /// </summary> /// <param name="dobj">The dependency object to monitor for changes.</param> /// <param name="dprop">The dependency property for which to stop receiving change notifications.</param> /// <param name="subscriber">The subscriber that wishes to stop receiving change notifications for the specified dependency property.</param> internal static void UnregisterChangeNotification(DependencyObject dobj, DependencyProperty dprop, IDependencyPropertyChangeNotificationSubscriber subscriber) { Contract.Require(dobj, nameof(dobj)); Contract.Require(dprop, nameof(dprop)); Contract.Require(subscriber, nameof(subscriber)); dprop.changeNotificationServer.Unsubscribe(dobj, subscriber); }
/// <summary> /// Registers the specified subscriber to receive change notifications for the specified dependency property. /// </summary> /// <param name="dobj">The dependency object to monitor for changes.</param> /// <param name="dprop">The dependency property for which to receive change notifications.</param> /// <param name="subscriber">The subscriber that wishes to receive change notifications for the specified dependency property.</param> internal static void RegisterChangeNotification(DependencyObject dobj, DependencyProperty dprop, IDependencyPropertyChangeNotificationSubscriber subscriber) { Contract.Require(dobj, nameof(dobj)); Contract.Require(dprop, nameof(dprop)); Contract.Require(subscriber, nameof(subscriber)); dprop.changeNotificationServer.Subscribe(dobj, subscriber); }