Exemple #1
0
        /// <summary>
        /// The internals for setProperty() and related calls, used after the node is
        /// found or created.
        /// </summary>
        /// <param name="node">the newly created node</param>
        /// <param name="value">the node value, can be <c>null</c></param>
        /// <param name="newOptions">options for the new node, must not be <c>null</c>.</param>
        /// <param name="deleteExisting">flag if the existing value is to be overwritten</param>
        /// <exception cref="XmpException">thrown if options and value do not correspond</exception>
        internal static void SetNode(XmpNode node, object value, PropertyOptions newOptions, bool deleteExisting)
        {
            if (deleteExisting)
            {
                node.Clear();
            }

            // its checked by setOptions(), if the merged result is a valid options set
            node.Options.MergeWith(newOptions);

            if (!node.Options.IsCompositeProperty)
            {
                // This is setting the value of a leaf node.
                XmpNodeUtils.SetNodeValue(node, value);
            }
            else
            {
                if (value != null && value.ToString().Length > 0)
                {
                    throw new XmpException("Composite nodes can't have values", XmpErrorCode.BadXPath);
                }

                node.RemoveChildren();
            }
        }