Beispiel #1
0
        /// <summary>
        /// this version will first fetch the struct before getting/setting values on it when invoking the getter/setter
        /// </summary>
        /// <returns>The struct target.</returns>
        /// <param name="target">Target.</param>
        /// <param name="structName">Struct name.</param>
        /// <param name="field">Field.</param>
        public void SetStructTarget(object target, AbstractTypeInspector parentInspector, PropertyInfo prop)
        {
            _target     = target;
            _memberInfo = prop;
            _name       = prop.Name;
            _valueType  = prop.PropertyType;
            _isReadOnly = !prop.CanWrite || parentInspector._isReadOnly;

            _getter = obj =>
            {
                var structValue = parentInspector.GetValue();
                return(ReflectionUtils.GetPropertyGetter(prop).Invoke(structValue, null));
            };

            if (!_isReadOnly)
            {
                _setter = (val) =>
                {
                    var structValue = parentInspector.GetValue();
                    prop.SetValue(structValue, val);
                    parentInspector.SetValue(structValue);
                };
            }
        }
Beispiel #2
0
        /// <summary>
        /// this version will first fetch the struct before getting/setting values on it when invoking the getter/setter
        /// </summary>
        /// <returns>The struct target.</returns>
        /// <param name="target">Target.</param>
        /// <param name="structName">Struct name.</param>
        /// <param name="field">Field.</param>
        public void SetStructTarget(object target, AbstractTypeInspector parentInspector, FieldInfo field)
        {
            _target     = target;
            _memberInfo = field;
            _name       = field.Name;
            _valueType  = field.FieldType;
            _isReadOnly = field.IsInitOnly || parentInspector._isReadOnly;

            _getter = obj =>
            {
                var structValue = parentInspector.GetValue();
                return(field.GetValue(structValue));
            };

            if (!_isReadOnly)
            {
                _setter = val =>
                {
                    var structValue = parentInspector.GetValue();
                    field.SetValue(structValue, val);
                    parentInspector.SetValue(structValue);
                };
            }
        }