Exemple #1
0
        /// <summary>
        ///     Pretend the set on the property object was called
        ///     This will invoke the normal set, going through all the registered setters
        /// </summary>
        /// <param name="propertyName">Name of the property to set</param>
        /// <param name="value">Value to set</param>
        public void Set(string propertyName, object value)
        {
            var propertyInfo = PropertyTypes[propertyName];

            var hasOldValue = _properties.TryGetValue(propertyName, out var oldValue);
            var setInfo     = new SetInfo
            {
                Interceptor  = this,
                PropertyName = propertyName,
                PropertyType = propertyInfo,
                CanContinue  = true,
                NewValue     = value,
                HasOldValue  = hasOldValue,
                OldValue     = oldValue
            };

            foreach (var setter in _setters)
            {
                setter.SetterAction(setInfo);
                if (!setInfo.CanContinue || setInfo.Error != null)
                {
                    break;
                }
            }
            if (setInfo.HasError && setInfo.Error != null)
            {
                throw setInfo.Error;
            }
        }
Exemple #2
0
        /// <summary>
        ///     A default implementation of the set logic
        /// </summary>
        /// <param name="setInfo">SetInfo</param>
        private void DefaultSet(SetInfo setInfo)
        {
            var propertyType = PropertyTypes[setInfo.PropertyName];

            var newValue = propertyType.ConvertOrCastValueToType(setInfo.NewValue);

            // Add the value to the dictionary
            setInfo.Interceptor.Properties[setInfo.PropertyName] = newValue;
        }