Example #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, FieldInfo field)
        {
            _target     = target;
            _memberInfo = field;
            _name       = field.Name;
            _valueType  = field.FieldType;

            _getter = () =>
            {
                var structValue = parentInspector.getValue();
                return(field.GetValue(structValue));
            };
            _setter = (val) =>
            {
                var structValue = parentInspector.getValue();
                field.SetValue(structValue, val);
                parentInspector.setValue(structValue);
            };
        }
Example #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, PropertyInfo prop)
        {
            _target     = target;
            _memberInfo = prop;
            _name       = prop.Name;
            _valueType  = prop.PropertyType;

            _getter = () =>
            {
                var structValue = parentInspector.getValue();
                return(ReflectionUtils.getPropertyGetter(prop).Invoke(structValue, null));
            };
            _setter = (val) =>
            {
                var structValue = parentInspector.getValue();
                prop.SetValue(structValue, val);
                parentInspector.setValue(structValue);
            };
        }
Example #3
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);
                };
            }
        }