Exemple #1
0
        /// <summary>
        /// Sets a property value based on an expression
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value">The value.</param>
        /// <param name="propertyExpression">Primary Property To Update</param>
        /// <param name="secondaryExpressions">Additional Properties to notify of change</param>
        protected virtual void Set <T>(T value, Expression <Func <T> > propertyExpression, params Expression <Func <object> >[] secondaryExpressions)
        {
            if (propertyExpression == null)
            {
                return;
            }

            var propertyName = GetPropertyName(propertyExpression);

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                return;
            }

            // notify self
            OnNotifyPropertyChanging(propertyName);

            // notify linked
            foreach (var prop in secondaryExpressions)
            {
                PropertyChanging.NotifyPropertyChanging(prop);
            }

            // set value
            _valueDictionary[propertyName] = value;

            // notify self
            OnNotifyPropertyChanged(propertyName);

            // notify linked
            foreach (var prop in secondaryExpressions)
            {
                PropertyChanged.NotifyPropertyChanged(prop);
            }
        }