/// <summary> /// Private copy constructor. Used by <see cref="CreateNew" />. /// </summary> private NestedPropertyChangedNotifier(NestedPropertyChangedNotifier <T> copyFrom, T obj) { CascadeNotifications = copyFrom.CascadeNotifications; depth = copyFrom.depth; properties = new Dictionary <string, NestedPropertyDescriptor>(copyFrom.properties); notifiers = new Dictionary <string, InnerNotifier>(); var npcPds = properties.Select(p => p.Value).Where(npd => typeof(INotifyPropertyChanged).IsAssignableFrom(npd.PropertyType) && npd.PropertyDepth != depth); foreach (var npd in npcPds) { var notifier = new InnerNotifier(npd); notifiers[npd.Name] = notifier; notifier.PropertyChanged += NestedPropertyChanged; } Object = obj; }
/// <summary> /// Create a new <see cref="NestedPropertyChangeNotifier{T}" /> for type T and the /// given depth of nested properties. /// </summary> public NestedPropertyChangedNotifier(int depth = 1) { CascadeNotifications = true; this.depth = depth; var pds = NestedPropertyDescriptor.GetNestedProperties(typeof(T), depth); properties = pds.ToDictionary(pd => pd.Name); var npcPds = pds.Where(npd => typeof(INotifyPropertyChanged).IsAssignableFrom(npd.PropertyType) && npd.PropertyDepth != depth); notifiers = new Dictionary <string, InnerNotifier>(); foreach (var npd in npcPds) { var notifier = new InnerNotifier(npd); notifiers[npd.Name] = notifier; notifier.PropertyChanged += NestedPropertyChanged; } }