Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <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 applyOnChange = Flags.HasFlag(SerializableFieldAttributes.ApplyOnDirty) ||
                                 Flags.HasFlag(SerializableFieldAttributes.PassByCopy);

            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 ((applyOnChange || parentObject.GetType().IsValueType) && parent.parentProperty != null)
                    {
                        parent.parentProperty.SetValue(parentObject);
                    }
                }
            };

            SerializableProperty newProperty = Internal_CreateProperty(mCachedPtr);

            newProperty.Construct(type, internalType, getter, setter);

            return(newProperty);
        }