private void RemoveTreeSubscription(PropertyNotifier <T> tree)
 {
     foreach (var item in ReferenceCountTracker.Items)
     {
         tree.UnsubscribeFromChanges(item);
     }
 }
 private void SetupTreeSubscription(PropertyNotifier <T> tree)
 {
     foreach (var item in ReferenceCountTracker.Items)
     {
         tree.SubscribeToChanges(item);
     }
 }
Example #3
0
        private static void OnItemChanged(PropertyNotifier <T> tree, object itemThatChanged, PropertyChangedEventArgs args)
        {
            var itemChanged = tree.ItemChanged;

            if (itemChanged != null)
            {
                itemChanged(tree, (T)itemThatChanged, args);
            }
        }
Example #4
0
        private static void OnItemChanging(PropertyNotifier <T> tree, object itemThatIsChanging, PropertyChangingEventArgs args)
        {
            var itemChanging = tree.ItemChanging;

            if (itemChanging != null)
            {
                itemChanging(tree, (T)itemThatIsChanging, args);
            }
        }
        /// <summary>
        /// Adds a property to monitor for change events.
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="expression">The expression that points to the property</param>
        /// <returns>Property Notifier used to register change events on</returns>
        public PropertyNotifier <T> AddProperty <TResult>(Expression <Func <T, TResult> > expression)
        {
            var tree = PropertyNotifier <T> .Create(expression);

            _Properties.Add(tree);

            SetupTreeSubscription(tree);

            return(tree);
        }
        /// <summary>
        /// Stops listening for change events on the specified property
        /// </summary>
        /// <param name="tree"></param>
        /// <returns></returns>
        public bool RemoveProperty(PropertyNotifier <T> tree)
        {
            var removed = _Properties.Remove(tree);

            if (removed)
            {
                RemoveTreeSubscription(tree);
            }

            return(removed);
        }