Beispiel #1
0
        /// <summary>
        /// Implementors need to override this to save the indicated value.
        /// </summary>
        /// <param name="value">The value to be saved. A null will set the value to null. </param>
        /// <param name="mode">Indicates special handling for the action. Ignores SetAsOriginal.</param>
        /// <param name="propertyName">Name of property to update</param>
        /// <param name="oldValue">The previously stored value. If the property was uninitialized, this will return NotSet.Value</param>
        /// <returns>
        /// True if the value actually changed
        /// </returns>
        /// <exception cref="ArgumentNullException">propertyName;propertyName is null</exception>
        /// <exception cref="ArgumentException">propertyName is empty.;propertyName</exception>
        /// <remarks>
        /// This will create the property if it doesn't already exist
        /// </remarks>
        public override bool Set(object value, PropertySetModes mode, string propertyName, out object oldValue)
        {
            if (string.IsNullOrEmpty(propertyName))
                throw new ArgumentException($"{nameof(propertyName)} is null or empty.", nameof(propertyName));

            var property = Metadata.Properties[propertyName];

            if (mode.HasFlag(PropertySetModes.FixCasing))
                propertyName = property.Name;

            oldValue = GetValue(propertyName);

            if (Equals(oldValue, value))
                return false;

            m_Values[propertyName] = value;

            if (mode.HasFlag(PropertySetModes.RaiseChangedEvent))
                OnPropertyChanged(property);

            if (mode.HasFlag(PropertySetModes.ValidateProperty))
                OnRevalidateProperty(property);

            if (mode.HasFlag(PropertySetModes.ValidateObject))
                OnRevalidateObject();

            return true;
        }
Beispiel #2
0
        /// <summary>
        /// Implementors need to override this to save the indicated value.
        /// </summary>
        /// <param name="value">The value to be saved. A null will set the value to null.</param>
        /// <param name="mode">Indicates special handling for the action.</param>
        /// <param name="propertyName">Name of property to update</param>
        /// <param name="oldValue">The previously stored value. If the property was uninitialized, this will return NotSet.Value</param>
        /// <returns>
        /// True if the value actually changed
        /// </returns>
        /// <exception cref="ArgumentNullException">propertyName;propertyName is null</exception>
        /// <exception cref="ArgumentException">propertyName is empty.;propertyName</exception>
        /// <remarks>
        /// This will create the property if it doesn't already exist
        /// </remarks>
        public override bool Set(object value, PropertySetModes mode, string propertyName, out object oldValue)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentException($"{nameof(propertyName)} is null or empty.", nameof(propertyName));
            }

            var property = Metadata.Properties[propertyName];

            if (mode.HasFlag(PropertySetModes.FixCasing))
            {
                propertyName = property.Name;
            }

            oldValue = GetValue(propertyName);

            if (Equals(oldValue, value))
            {
                return(false);
            }

            if (mode.HasFlag(PropertySetModes.SetAsOriginal))
            {
                m_OriginalValues[propertyName] = value;
            }

            if (mode.HasFlag(PropertySetModes.RaiseChangedEvent))
            {
                OnPropertyChanging(property);
            }

            Values[propertyName] = value;

            UpdateChangeTrackingEventHandlers(oldValue, value);

            if (mode.HasFlag(PropertySetModes.RaiseChangedEvent))
            {
                OnPropertyChanged(property);
            }

            if (mode.HasFlag(PropertySetModes.UpdateIsChangedProperty))
            {
                IsChangedLocal = true;
            }

            if (mode.HasFlag(PropertySetModes.ValidateProperty))
            {
                OnRevalidateProperty(property);
            }

            if (mode.HasFlag(PropertySetModes.ValidateObject))
            {
                OnRevalidateObject();
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Set the indicated property to the value.
        /// If the value doesn't match the previous value, or if there is no previous value, raise a property changed notification.
        /// </summary>
        /// <param name="value">Value to be saved.</param>
        /// <param name="mode">Indicates special handling for the action.</param>
        /// <param name="propertyName">Name of property to be created/updated</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">propertyName;propertyName is null</exception>
        /// <exception cref="ArgumentException">propertyName is empty.;propertyName</exception>
        public bool Set(object value, PropertySetModes mode, [CallerMemberName] string propertyName = null)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentException($"{nameof(propertyName)} is null or empty.", nameof(propertyName));
            }

            return(Set(value, mode, propertyName, out var oldValue));
        }
Beispiel #4
0
 public override bool Set(object value, PropertySetModes mode, string propertyName, out object oldValue)
 {
     oldValue = null;
     m_Values[propertyName] = value;
     return(true);
 }
Beispiel #5
0
 public abstract bool Set(object value, PropertySetModes mode, string propertyName, out object oldValue);