Exemplo n.º 1
0
        /// <summary> First property depends on the changed value of the second property.
        ///		If the second property (subject) is set using SetProperty, then the dependent (observer) property will be notified as well.
        /// <example>
        ///					AddPropertyDependency(() => ThisProperty, () => DependsOnThisProperty);
        /// </example>
        ///		The benefits of this is that we can SEE DIRECTLY in the code which property is related to what.
        ///		DO NOT use RaiseDependentPropertyChanged because it's HARDER to see which property is related to which property.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="U"></typeparam>
        /// <param name="observerProperty"></param>
        /// <param name="subjectProperty"></param>
        protected void AddPropertyDependency(string dependentName, string sourceName)
        {
            if (_propertyDependencies == null)
            {
                _propertyDependencies = new Dictionary <string, HashSet <string> >();
            }

            //TODO: Check for recursion.

            if (dependentName == sourceName)
            {
                throw new ArgumentOutOfRangeException("dependentProperty", "The dependent and source property cannot be the same.");
            }

            HashSet <string> dependents = CacheUtility.FindInCacheOrAdd(_propertyDependencies, sourceName, () => new HashSet <string>());

            if (!dependents.Contains(dependentName))
            {
                dependents.Add(dependentName);
            }
        }