/// <summary> /// It is intended to be used as the implementation of the <b>set</b> accessors of the properties on the inheritor ViewModel class. It returns the value set using <see cref="SetValue{T}(T, string)"/> /// </summary> /// <typeparam name="T">Type of the property</typeparam> /// <param name="value">The value assigned to the property</param> /// <param name="propertyName">Name of the property</param> /// <remarks> /// This method ensures the following in order: /// - Apply validations on the property. <see cref="ViewModelPropertyDescriptor{TOwner, TResult}.ValidateAlways"/>, <see cref="HasErrors"/>, <see cref="GetValidationResults(string)"/> /// - Apply coerce on new values /// - Validate coerced values if desired /// - Assign value to the property /// - Apply value setters on the property /// - Record the property set if the property assignation is in an edition scope /// - Notify property change when property is not in an edition scope /// </remarks> protected virtual bool SetValue <T>(T value, [CallerMemberName] string propertyName = null) { if (!_values.TryGetValue(propertyName, out IViewModelProperty prop)) { if (!PropertyDescriptors.ContainsKey(propertyName)) { PropertyDescriptors.Add(propertyName, new ViewModelPropertyDescriptor <TInheritor, T>(propertyName)); } prop = new ViewModelProperty <TInheritor, T>(); _values.Add(propertyName, prop); } return(((ViewModelProperty <TInheritor, T>)prop).SetValue((TInheritor)this, propertyName, value)); }
protected virtual void SetCollection <T>(T collection, [CallerMemberName] string propertyName = null) where T : ICollection, INotifyCollectionChanged { if (!_values.TryGetValue(propertyName, out IViewModelProperty prop)) { if (!PropertyDescriptors.ContainsKey(propertyName)) { PropertyDescriptors.Add(propertyName, new ViewModelCollectionPropertyDescriptor <TInheritor, T>(propertyName)); } prop = new ViewModelCollectionProperty <TInheritor, T>(); _values.Add(propertyName, prop); } ((ViewModelCollectionProperty <TInheritor, T>)prop).SetValue((TInheritor)this, propertyName, collection); }