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 void TrackProperties(params Expression <Func <object> >[] expressions)
        {
            foreach (var expression in expressions)
            {
                var propertyName  = PropertySupport.ExtractPropertyName(expression);
                var propertyValue = PropertySupport.GetPropertyValue <object, dynamic>(this, propertyName);

                _initialValues[propertyName] = propertyValue;
                OnValidate(propertyName);
            }
        }
Example #3
0
        public bool CheckIsPropertyChanged(string propertyName)
        {
            var initialValue = _initialValues[propertyName];
            var actualValue  = PropertySupport.GetPropertyValue <object, dynamic>(this, propertyName);

            if (actualValue is IStorableBladeModel storableBladeModel)
            {
                return(storableBladeModel.IsChanged);
            }
            else
            {
                return(!PropertySupport.CompareHelper.AreEquals(actualValue, initialValue));
            }
        }