Example #1
0
        /// <summary>
        /// Sets value to the Model object's property
        /// </summary>
        /// <typeparam name="TObject"></typeparam>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="storageObject"></param>
        /// <param name="storageObjectPropertyExpression"></param>
        /// <param name="value"></param>
        /// <param name="propertyName"></param>
        /// <param name="userInput"></param>
        /// <returns></returns>
        protected bool SetProperty <TObject, TProperty>(TObject storageObject,
                                                        Expression <Func <dynamic> > storageObjectPropertyExpression, TProperty value,
                                                        [CallerMemberName] string propertyName = null, bool userInput = false)
        {
            if (userInput && !_userInput.Contains(propertyName))
            {
                _userInput.Add(propertyName);
            }

            var storagePropertyName = PropertySupport.ExtractPropertyName(storageObjectPropertyExpression);

            dynamic val = PropertySupport.GetPropertyValue <TObject, TProperty>(storageObject, storagePropertyName);

            if ((val as object)?.GetType().IsValueType ?? false && val != null && value != null)
            {
                if (val.Equals(value))
                {
                    return(false);
                }
            }
            else if (val == value)
            {
                return(false);
            }

            PropertySupport.SetPropertyValue(storageObject, storagePropertyName, value);

            {
                Invalidate(propertyName);
            }

            return(true);
        }
Example #2
0
 public virtual void ResetChanges()
 {
     foreach (var propertyName in _initialValues.Keys)
     {
         var initialValue = _initialValues[propertyName];
         if (initialValue is IStorableBladeModel storableBladeModel)
         {
             storableBladeModel.ResetChanges();
         }
         else
         {
             PropertySupport.SetPropertyValue <object, dynamic>(this, propertyName, initialValue);
         }
     }
 }