Example #1
0
 /// <summary>
 /// Constructs the object; remembers the callers' type for looking up dependent properties
 /// efficiently
 /// </summary>
 /// <param name="callerType">The callers (i.e. derived class) type</param>
 protected NotifyPropertyChangedImpl(Type callerType)
 {
     if (DependentProperties.ContainsKey(callerType))
     {
         CallerType = callerType;
     }
 }
Example #2
0
        /// <summary>
        /// Add a group of interdependent properties (i.e. if one of them changes, all of them change)
        /// </summary>
        /// <typeparam name="Type">The type</typeparam>
        /// <param name="propertyNamesDest">The list of property names</param>
        protected static void AddDependencyGroup <Type>(params string[] propertyNamesDest)
        {
            var type = typeof(Type);

            if (!ValidatePublicPropertyNames(type, propertyNamesDest))
            {
                throw new ArgumentException("A destination property is not a property of the given type", "propertyNamesDest");
            }

            if (!DependentProperties.ContainsKey(type))
            {
                DependentProperties[type] = new Dictionary <string, List <string> >();
            }

            foreach (var propertyNameSource in propertyNamesDest)
            {
                if (!DependentProperties[type].ContainsKey(propertyNameSource))
                {
                    DependentProperties[type][propertyNameSource] = new List <string>();
                }

                foreach (var name in propertyNamesDest)
                {
                    if (name == propertyNameSource)
                    {
                        continue;
                    }
                    if (DependentProperties[type][propertyNameSource].Any(item => item == name))
                    {
                        continue;
                    }
                    DependentProperties[type][propertyNameSource].Add(name);
                }
            }
        }