internal PropertyTracker(IPropertyPathTracker pathTracker, NotifyingGetter <TSource, TValue> getter) { var type = getter.Property.ReflectedType; if (type is null) { throw new ArgumentException("getter.Property.ReflectedType is null"); } if (type.IsValueType) { var message = $"Property path cannot have structs in it. Copy by value will make subscribing error prone.{Environment.NewLine}" + $"The type {type.Namespace}.{type.PrettyName()} is a value type not so {type.PrettyName()}.{getter.Property.Name} subscribing to changes is weird."; throw new ArgumentException(message, nameof(getter)); } if (!typeof(INotifyPropertyChanged).IsAssignableFrom(type)) { var message = $"All levels in the path must implement INotifyPropertyChanged.{Environment.NewLine}" + $"The type {type.Namespace}.{type.PrettyName()} does not so the property {type.PrettyName()}.{getter.Property.Name} will not notify when value changes."; throw new ArgumentException(message, nameof(getter)); } this.PathTracker = pathTracker; this.Getter = getter; this.onTrackedPropertyChanged = (o, e) => { if (e.IsMatch(getter.Property)) { this.OnTrackedPropertyChanged(o, e); } }; }
public PropertyTracker(IPropertyPathTracker pathTracker, NotifyingGetter <TSource, TValue> getter) { Ensure.NotNull(pathTracker, nameof(pathTracker)); Ensure.NotNull(getter, nameof(getter)); Ensure.NotNull(getter.Property.ReflectedType, nameof(getter)); var type = getter.Property.ReflectedType; if (type == null) { throw new ArgumentException("PathProperty.ReflectedType == null"); } if (type.IsValueType) { var message = string.Format( "Property path cannot have structs in it. Copy by value will make subscribing error prone." + Environment.NewLine + "The type {0}.{1} is a value type not so {1}.{2} subscribing to changes is weird.", type.Namespace, type.PrettyName(), getter.Property.Name); throw new ArgumentException(message, nameof(getter)); } if (!typeof(INotifyPropertyChanged).IsAssignableFrom(type)) { var message = string.Format( "All levels in the path must implement INotifyPropertyChanged." + Environment.NewLine + "The type {0}.{1} does not so the property {1}.{2} will not notify when value changes.", type.Namespace, type.PrettyName(), getter.Property.Name); throw new ArgumentException(message, nameof(getter)); } this.PathTracker = pathTracker; this.Getter = getter; this.onTrackedPropertyChanged = (o, e) => { if (NotifyPropertyChangedExt.IsMatch(e, this.Getter.Property)) { this.OnTrackedPropertyChanged(o, e); } }; }