Exemple #1
0
        protected void SubscriptionAction(PropertyChangedPubSubPayload payload)
        {
            if (!payload.Source.TryGetTarget(out IPropertyChangedPubSubViewModel source))
            {
                return;
            }

            // Prevent an object reacting to its own notifications.
            if (source.InstanceId == InstanceId)
            {
                return;
            }

            Dictionary <string, HashSet <string> > sourceSubscribedProperties = m_SourceSubscribedPropertyNames.GetOrCreateValue(source);

            if (!sourceSubscribedProperties.TryGetValue(payload.PropertyName, out HashSet <string> subscribedPropertyTargets))
            {
                return;
            }

            foreach (string target in subscribedPropertyTargets)
            {
                RaisePropertyChanged(target);
            }
        }
        protected bool SubscriptionFilter(PropertyChangedPubSubPayload payload)
        {
            if (payload is null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            if (!payload.Source.TryGetTarget(out IPropertyChangedPubSubViewModel source))
            {
                return(false);
            }

            // Prevent an object reacting to its own notifications.
            if (source.InstanceId == InstanceId)
            {
                return(false);
            }

            Dictionary <string, HashSet <string> > sourceSubscribedProperties = m_SourceSubscribedPropertyNames.GetOrCreateValue(source);

            // Only proceed if object is subscribed to source property name.
            if (!sourceSubscribedProperties.TryGetValue(payload.PropertyName, out HashSet <string> subscribedPropertyTargets))
            {
                return(false);
            }

            return(true);
        }