Beispiel #1
0
            public bool MoveNext()
            {
                if (++_index >= _properties.Count)
                {
                    return(false);
                }

                var property = _properties[_index];

                if (property.IsReadOnly)
                {
                    _current = new ManagedPropertyField
                    {
                        _property = property,
                        _value    = (property as IManagedPropertyInternal).ProvideReadOnlyValue(_mpo)
                    };
                }
                else
                {
                    _current = _mpo._compiledFields[property.TypeCompiledIndex];
                    if (!_current.HasValue)
                    {
                        _current = new ManagedPropertyField
                        {
                            _property = property,
                            _value    = property.GetMeta(_mpo).DefaultValue
                        };
                    }
                }

                return(true);
            }
Beispiel #2
0
 internal CompiledPropertyValuesEnumerator(ManagedPropertyObject mpo)
 {
     _index      = -1;
     _mpo        = mpo;
     _current    = new ManagedPropertyField();
     _properties = mpo.PropertiesContainer.GetCompiledProperties();
 }
Beispiel #3
0
        /// <summary>
        /// LoadProperty 直接设置值,不发生 PropertyChanged 事件。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        private void _LoadProperty(IManagedProperty property, object value)
        {
            CheckEditing(property);

            value = CoerceType(property, value);

            if (NeedReset(property, value))
            {
                this._ResetProperty(property);
                return;
            }

            if (property.LifeCycle == ManagedPropertyLifeCycle.Compile)
            {
                this._compiledFields[property.TypeCompiledIndex]._value = value;
            }
            else
            {
                if (this._runtimeFields == null)
                {
                    this._runtimeFields = new Dictionary <IManagedProperty, ManagedPropertyField>();
                }

                var field = new ManagedPropertyField
                {
                    _property = property,
                    _value    = value
                };
                this._runtimeFields[property] = field;
            }
        }
Beispiel #4
0
 internal NonDefaultPropertyValuesEnumerator(ManagedPropertyObject mpo)
 {
     _index                  = -1;
     _mpo                    = mpo;
     _current                = new ManagedPropertyField();
     _runtimeFields          = null;
     _enumerateRuntimeFields = false;
 }
Beispiel #5
0
            public bool MoveNext()
            {
                if (++_index >= _properties.Count)
                {
                    return(false);
                }

                var property = _properties[_index];

                _current = _mpo._compiledFields[property.TypeCompiledIndex];
                if (!_current.HasValue)
                {
                    _current = new ManagedPropertyField
                    {
                        _property = property,
                        _value    = property.GetMeta(_mpo).DefaultValue
                    };
                }

                return(true);
            }
Beispiel #6
0
            public bool MoveNext()
            {
                _index++;

                var compiledFields = _mpo._compiledFields;

                //编译期属性
                var compiledFieldLength = compiledFields.Length;

                while (_index < compiledFieldLength)
                {
                    var field = compiledFields[_index];
                    if (field.HasValue)
                    {
                        var defaultValue = field.Property.GetMeta(this).DefaultValue;
                        if (!object.Equals(field.Value, defaultValue))
                        {
                            _current = field;
                            return(true);
                        }
                    }

                    _index++;
                }

                //第一次进入运行时属性遍历
                if (!_enumerateRuntimeFields)
                {
                    var rf = _mpo._runtimeFields;
                    if (rf != null)
                    {
                        var values = rf.Values;
                        _runtimeFields = new ManagedPropertyField[values.Count];
                        values.CopyTo(_runtimeFields, 0);
                    }

                    _enumerateRuntimeFields = true;
                }

                //开始遍历运行时属性。
                if (_runtimeFields != null)
                {
                    var runtimeFieldsCount = _runtimeFields.Length;
                    while (true)
                    {
                        var runtimeIndex = _index - compiledFieldLength;
                        if (runtimeIndex >= runtimeFieldsCount)
                        {
                            break;
                        }

                        var field = _runtimeFields[runtimeIndex];
                        if (field.HasValue)
                        {
                            var defaultValue = field.Property.GetMeta(this).DefaultValue;
                            if (!object.Equals(field.Value, defaultValue))
                            {
                                _current = field;
                                return(true);
                            }
                        }

                        _index++;
                    }
                }

                return(false);
            }
Beispiel #7
0
        /// <summary>
        /// 设置某个属性的值。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        /// <param name="source"></param>
        /// <returns>返回最终使用的值。</returns>
        private object _SetProperty(IManagedProperty property, object value, ManagedPropertyChangedSource source)
        {
            object finalValue = null;

            CheckEditing(property);

            var meta = property.GetMeta(this) as IManagedPropertyMetadataInternal;

            finalValue = meta.DefaultValue;

            value = CoerceType(property, value);

            bool isReset = false;

            if (NeedReset(property, value))
            {
                isReset = true;
                value   = meta.DefaultValue;
            }

            bool cancel = meta.RaisePropertyChangingMetaEvent(this, ref value, source);

            if (!cancel)
            {
                bool   hasOldValue = false;
                object oldValue    = null;

                //这个 if 块中的代码:查找或创建对应 property 的 field,同时记录可能存在的历史值。
                if (property.LifeCycle == ManagedPropertyLifeCycle.Compile)
                {
                    var index = property.TypeCompiledIndex;
                    var field = this._compiledFields[index];
                    if (field.HasValue)
                    {
                        oldValue    = field.Value;
                        hasOldValue = true;
                    }

                    if (isReset)
                    {
                        this._compiledFields[index].ResetValue();
                    }
                    else
                    {
                        this._compiledFields[index]._value = value;
                    }
                }
                else
                {
                    if (this._runtimeFields == null)
                    {
                        if (!isReset)
                        {
                            this._runtimeFields = new Dictionary <IManagedProperty, ManagedPropertyField>();
                        }
                    }
                    else
                    {
                        var oldField = new ManagedPropertyField();
                        if (this._runtimeFields.TryGetValue(property, out oldField))
                        {
                            oldValue    = oldField.Value;
                            hasOldValue = true;
                        }
                    }

                    if (isReset)
                    {
                        if (hasOldValue)
                        {
                            this._runtimeFields.Remove(property);
                        }
                    }
                    else
                    {
                        //使用新的 field
                        var field = new ManagedPropertyField
                        {
                            _property = property,
                            _value    = value
                        };
                        if (hasOldValue)
                        {
                            this._runtimeFields[property] = field;
                        }
                        else
                        {
                            this._runtimeFields.Add(property, field);
                        }
                    }
                }

                if (!hasOldValue)
                {
                    oldValue = meta.DefaultValue;
                }

                if (!object.Equals(oldValue, value))
                {
                    var args = new ManagedPropertyChangedEventArgs(property, oldValue, value, source);

                    //发生 Meta 中的回调事件
                    meta.RaisePropertyChangedMetaEvent(this, args);

                    //发生外部事件
                    this.RaisePropertyChanged(args);

                    finalValue = value;
                }
            }

            return(finalValue);
        }