private PropertyChainEntry BuildChainEntry <T>(INotifyPropertyChanged observedInstance, PropertyChainEntry parent, PropertyInfo observedProperty, IEnumerable <PropertyInfo> remainingChain, Action <T, T> callback)
        {
            if (remainingChain == null || remainingChain.None())
            {
                return(BuildLastChainEntry(observedInstance, parent, observedProperty, callback));
            }

            var entry        = new PropertyChainEntry(observedInstance, observedProperty, parent);
            var nextInstance = GetNextInstance(observedInstance, observedProperty);

            entry.NextEntry = BuildChainEntry(nextInstance, entry, remainingChain.First(), remainingChain.Skip(1).ToArray(), callback);

            return(entry);
        }
 public PropertyChainEntry(INotifyPropertyChanged observedInstance, PropertyInfo observedProperty, PropertyChainEntry parent)
 {
     ObservedProperty = observedProperty;
     ObservedInstance = observedInstance;
     Parent           = parent;
 }
 public LastPropertyChainEntry(INotifyPropertyChanged observedInstance, PropertyInfo observedProperty, PropertyChainEntry parent) :
     base(observedInstance, observedProperty, parent)
 {
     _isInitialized = true;
 }
 private PropertyChainEntry BuildLastChainEntry <T>(INotifyPropertyChanged observedInstance, PropertyChainEntry parent, PropertyInfo observedProperty, Action <T, T> callback)
 {
     return(new LastPropertyChainEntry <T>(observedInstance, observedProperty, parent)
     {
         Callback = callback
     });
 }
 private PropertyChainEntry BuildMiddleEntry(INotifyPropertyChanged observedInstance, PropertyChainEntry parent, PropertyInfo observedProperty)
 {
     return(new PropertyChainEntry(observedInstance, observedProperty, parent));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a listener that observes a property chain given by <paramref name="selectorExpression"/>
        /// and rooted in <paramref name="rootObject"/>, invoking <paramref name="callback"/> on change
        /// </summary>
        /// <param name="rootObject">root of the property chain</param>
        /// <param name="selectorExpression">expression pointing on a property to observe</param>
        /// <param name="callback">callback to invoke when property changes; first argument to the callback is the old value of the observed property, second argument is the new value</param>
        public PropertyChangedListener(TRoot rootObject, Expression <Func <TRoot, TProperty> > selectorExpression, Action <TProperty, TProperty> callback)
        {
            var memberChain = new MemberChainBuilder().BuildMemberChain(selectorExpression);

            _listenerChain = new ListenerChainBuilder().BuildListenerChain(rootObject, memberChain, callback);
        }