Exemple #1
0
        public void SetValueAndNotifyChange(object target, object value, IPropertyChangedSuscriber suscriber)
        {
            object oldValue = _getter(target);

            if (oldValue != value)
            {
                _setter(target, value);

                suscriber.OnPropertyChanged(target, PropertyName, oldValue, value);
            }
        }
Exemple #2
0
        /// <summary>
        /// Sets the value to the property of the target object and notifies the subscriber when the property has changed
        /// </summary>
        /// <param name="target">The object to set the property</param>
        /// <param name="propertyName">The name of the property to set</param>
        /// <param name="value">The value to set</param>
        /// <param name="subscriber">The subscriber that gets notified when a property changes in the object</param>
        public void SetValueAndNotifyChange(object target, string propertyName, object value, IPropertyChangedSuscriber subscriber)
        {
            PropertyAccessor propertyAccessor = PropertyAccessors[propertyName];

            if (!propertyAccessor.CanSet)
            {
                throw new InvalidOperationException($"Can not set the value of property: '{propertyAccessor.PropertyName}'.Verify that the declaring type is not a value type(such as struct)");
            }

            propertyAccessor.SetValueAndNotifyChange(target, value, subscriber);
        }