예제 #1
0
        public override object Read(object value, ProtoReader source)
        {
            Helpers.DebugAssert(value != null);

            object oldVal = Tail.RequiresOldValue
                                ? _accessors.Get != null?_accessors.Get(value) : Helpers.GetPropertyValue(_property, value)
                                : null;

            object newVal = Tail.Read(oldVal, source);

            if (_canSetInRuntime &&
                (!Tail.RequiresOldValue    // always set where can't check oldVal
                 // and if it's value type or nullable with changed null/not null or ref
                 || (Helpers.IsValueType(_property.PropertyType) && oldVal != null && newVal != null) ||
                 !ReferenceEquals(oldVal, newVal)
                ))
            {
                if (_accessors.Set != null)
                {
                    _accessors.Set(value, newVal);
                }
                else
                {
                    if (_shadowSetter == null)
                    {
                        _property.SetValue(value, newVal, null);
                    }
                    else
                    {
                        _shadowSetter.Invoke(value, new object[] { newVal });
                    }
                }
            }
            return(value);
        }
예제 #2
0
        public override object Read(object value, ProtoReader source)
        {
            Helpers.DebugAssert(value != null);
            object newVal = Tail.Read(Tail.RequiresOldValue ? GetValue(value) : null, source);

            if (_accessors.Set != null)
            {
                _accessors.Set(value, newVal);
            }
            else
            {
                _field.SetValue(value, newVal);
            }
            return(value);
        }