Exemplo n.º 1
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);
        }