/// <summary> /// Returns a serializable property for a specific list element. /// </summary> /// <param name="elementIdx">Index of the element in the list.</param> /// <returns>Serializable property that allows you to manipulate contents of the list entry.</returns> public SerializableProperty GetProperty(int elementIdx) { SerializableProperty.Getter getter = () => { IList list = parentProperty.GetValue <IList>(); if (list != null) { return(list[elementIdx]); } else { return(null); } }; SerializableProperty.Setter setter = (object value) => { IList list = parentProperty.GetValue <IList>(); if (list != null) { list[elementIdx] = value; } }; SerializableProperty property = Internal_CreateProperty(mCachedPtr); property.Construct(ElementPropertyType, elementType, getter, setter); return(property); }
/// <summary> /// Returns a serializable property for a specific array element. /// </summary> /// <param name="elementIdx">Index of the element in the array.</param> /// <returns>Serializable property that allows you to manipulate contents of the array entry.</returns> public SerializableProperty GetProperty(int elementIdx) { SerializableProperty.Getter getter = () => { Array array = parentProperty.GetValue <Array>(); if (array != null) { return(array.GetValue(elementIdx)); } else { return(null); } }; SerializableProperty.Setter setter = (object value) => { Array array = parentProperty.GetValue <Array>(); if (array != null) { array.SetValue(value, elementIdx); } }; SerializableProperty property = Internal_CreateProperty(mCachedPtr); property.Construct(ElementPropertyType, elementType, getter, setter); return(property); }
/// <summary> /// Returns a serializable property for the specified entry. /// </summary> /// <param name="key">Dictionary key for the value to retrieve.</param> /// <returns>Serializable property that allows you to manipulate contents of the dictionary entry.</returns> public KeyValuePair <SerializableProperty, SerializableProperty> GetProperty(object key) { IDictionary dictionary = parentProperty.GetValue <IDictionary>(); if (dictionary == null || !dictionary.Contains(key)) { return(new KeyValuePair <SerializableProperty, SerializableProperty>(null, null)); } SerializableProperty keyProperty; { SerializableProperty.Getter getter = () => key; SerializableProperty.Setter setter = (object value) => {}; keyProperty = Internal_CreateKeyProperty(mCachedPtr); keyProperty.Construct(KeyPropertyType, keyType, getter, setter); } SerializableProperty valueProperty; { SerializableProperty.Getter getter = () => { IDictionary dict = parentProperty.GetValue <IDictionary>(); if (dict != null) { return(dict[key]); } else { return(null); } }; SerializableProperty.Setter setter = (object value) => { IDictionary dict = parentProperty.GetValue <IDictionary>(); if (dict != null) { dict[key] = value; } }; valueProperty = Internal_CreateValueProperty(mCachedPtr); valueProperty.Construct(ValuePropertyType, valueType, getter, setter); } return(new KeyValuePair <SerializableProperty, SerializableProperty>(keyProperty, valueProperty)); }
/// <summary> /// Returns a serializable property for the field. /// </summary> /// <returns>Serializable property that allows you to manipulate contents of the field.</returns> public SerializableProperty GetProperty() { SerializableProperty.Getter getter = () => { object parentObject = parent.GetReferencedObject(); if (parentObject != null) { return(Internal_GetValue(mCachedPtr, parentObject)); } else { return(null); } }; bool parentApplyOnChildChanges = parent.parentProperty?.ApplyOnChildChanges ?? false; SerializableProperty.Setter setter = (object value) => { object parentObject = parent.GetReferencedObject(); if (parentObject != null) { Internal_SetValue(mCachedPtr, parentObject, value); // If value type we cannot just modify the parent object because it's just a copy if ((parentApplyOnChildChanges || parentObject.GetType().IsValueType) && parent.parentProperty != null) { parent.parentProperty.SetValue(parentObject); } } }; bool applyOnChildChanges = Flags.HasFlag(SerializableFieldAttributes.ApplyOnDirty) || Flags.HasFlag(SerializableFieldAttributes.PassByCopy) || parentApplyOnChildChanges; SerializableProperty newProperty = Internal_CreateProperty(mCachedPtr); newProperty.Construct(type, internalType, getter, setter, applyOnChildChanges); return(newProperty); }
/// <inheritdoc/> protected internal override object GetValue(int seqIndex) { SerializableArray serzArray = property.GetArray(); // Create a property wrapper for native arrays so we get notified when the array values change if (style.StyleFlags.HasFlag(InspectableFieldStyleFlags.NativeWrapper)) { SerializableProperty.Getter getter = () => { Array array = property.GetValue <Array>(); if (array != null) { return(array.GetValue(seqIndex)); } else { return(null); } }; SerializableProperty.Setter setter = (object value) => { Array array = property.GetValue <Array>(); if (array != null) { array.SetValue(value, seqIndex); property.SetValue(array); } }; return(new SerializableProperty(serzArray.ElementPropertyType, serzArray.ElementType, getter, setter)); } else { return(serzArray.GetProperty(seqIndex)); } }
/// <summary> /// Returns a serializable property for the field. /// </summary> /// <returns>Serializable property that allows you to manipulate contents of the field.</returns> public SerializableProperty GetProperty() { SerializableProperty.Getter getter = () => { object parentObject = parent.GetReferencedObject(); if (parentObject != null) { return(Internal_GetValue(mCachedPtr, parentObject)); } else { return(null); } }; SerializableProperty.Setter setter = (object value) => { object parentObject = parent.GetReferencedObject(); if (parentObject != null) { Internal_SetValue(mCachedPtr, parentObject, value); // If value type we cannot just modify the parent object because it's just a copy if (parentObject.GetType().IsValueType&& parent.parentProperty != null) { parent.parentProperty.SetValue(parentObject); } } }; SerializableProperty newProperty = Internal_CreateProperty(mCachedPtr); newProperty.Construct(type, internalType, getter, setter); return(newProperty); }