/// <summary> /// Creates a new <see cref="DerivedNotifyProperty<TValue>"/>. When any of the specified properties change in the owner object, this property's value will be re-calculated the next time it is requested /// </summary> /// <param name="owner">Object that contains this property and the ones from which it is derived</param> /// <param name="derivedPropertyName">Name of this property in the owner</param> /// <param name="getDerivedPropertyValue">Function to determine the current value of this property</param> /// <param name="propertiesDependedOn">Properties that this value depends on. When any of these properties change, this property's value will be re-calculated the next time it is requested. /// These properties must therefore be in the same owner object as this one.</param> public DerivedNotifyProperty(IRaisePropertyChanged owner, string derivedPropertyName, Func <TValue> getDerivedPropertyValue, params string[] propertiesDependedOn) : this(owner, derivedPropertyName, getDerivedPropertyValue) { this.m_owner.PropertyChanged += m_owner_PropertyChanged; if (propertiesDependedOn == null) { throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => propertiesDependedOn)); } this.m_dependentValuesToListenFor = propertiesDependedOn.ToDictionary(property => property, property => true); }
/// <summary> /// Creates a notify property with the given owner and name /// </summary> /// <param name="owner">Object that contains this property, on which <see cref="INotifyPropertyChanged.PropertyChanged"/> events will be raised</param> /// <param name="name">Name of the property within its owner</param> /// <param name="initialValue">Initial value of the property</param> /// <param name="itemChangedComparer">Comparer that will be used to determine if the value has changed</param> public NotifyProperty(IRaisePropertyChanged owner, string name, T initialValue, IEqualityComparer <T> itemChangedComparer) : this(owner, name) { if (itemChangedComparer == null) { throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => itemChangedComparer)); } this.m_itemChangedComparer = itemChangedComparer; this.m_value = initialValue; }
/// <summary> /// Creates a new <see cref="DerivedNotifyProperty<TValue>"/>. When any of the specified properties change, this property's value will be re-calculated the next time it is requested /// </summary> /// <param name="owner">Object that contains this property</param> /// <param name="derivedPropertyName">Name of this property in the owner</param> /// <param name="getDerivedPropertyValue">Function to determine the current value of this property</param> /// <param name="valueChangesToListenFor">Properties that this value depends on. When any of these properties change, this property's value will be re-calculated the next time it is requested.</param> public DerivedNotifyProperty(IRaisePropertyChanged owner, string derivedPropertyName, Func <TValue> getDerivedPropertyValue, params INotifyValueChanged[] valueChangesToListenFor) : this(owner, derivedPropertyName, getDerivedPropertyValue) { if (valueChangesToListenFor == null) { throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => valueChangesToListenFor)); } foreach (INotifyValueChanged valueChangeToListenFor in valueChangesToListenFor) { valueChangeToListenFor.ValueChanged += TriggerValueChanged; } }
/// <summary> /// Creates a notify property with the given owner and name /// </summary> /// <param name="owner">Object that contains this property, on which <see cref="INotifyPropertyChanged.PropertyChanged"/> events will be raised</param> /// <param name="name">Name of the property within its owner</param> public NotifyProperty(IRaisePropertyChanged owner, string name) { if (owner == null) { throw new NotSupportedException("Null owners (e.g. static properties) are not supported"); } if (string.IsNullOrEmpty(name)) { throw new ArgumentException("No property name was specified", ObjectNamingExtensions.GetName(() => name)); } this.m_owner = owner; this.m_name = name; this.m_itemChangedComparer = EqualityComparer <T> .Default; //will be overwritten by other constructors if necessary }
private DerivedNotifyProperty(IRaisePropertyChanged owner, string derivedPropertyName, Func <TValue> getDerivedPropertyValue) { if (owner == null) { throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => owner)); } this.m_owner = owner; if (string.IsNullOrEmpty(derivedPropertyName)) { throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => derivedPropertyName)); } this.m_derivedPropertyName = derivedPropertyName; if (getDerivedPropertyValue == null) { throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => getDerivedPropertyValue)); } this.m_getValueProperty = getDerivedPropertyValue; this.m_value = new Lazy <TValue>(m_getValueProperty); }