/// <summary>
        /// Adds the or update state data.
        /// </summary>
        /// <param name="targetData">The target data.</param>
        /// <returns></returns>
        internal PropertyCollection addOrUpdateStateData(PropertyCollection targetData = null)
        {
            if (targetData == null)
            {
                targetData = data;
            }

            targetData.setSystemStatus(this.getLastLine(), !targetData.containsKey(templateFieldBasic.sys_uid));

            targetData.addStringToMultikeys(directoryScope.FullName, false, templateFieldBasic.path_dir);
            targetData.addStringToMultikeys(directoryRoot.FullName, true, templateFieldBasic.path_output);

            //targetData.addStringToMultikeys(render, false, templateFieldBasic.path_format);
            if (script != null)
            {
                if (!script.flags.HasFlag(docScriptFlags.enableLocalCollection))
                {
                    IMetaContentNested mc = scope as IMetaContentNested;

                    var changes = scope_monitor.getState(true);

                    if (changes.IsTargetChanged)
                    {
                        if (changes.IsParentChanged)
                        {
                            var tmpData = mc.AppendDataFields();
                            targetData.AddRange(tmpData, false);
                        }
                        else
                        {
                            mc.AppendDataFields(targetData);
                        }
                    }
                }
            }

            return(targetData);
        }
        /// <summary>
        /// Combines two PropertyCollections according <c>policy</c> specified
        /// </summary>
        /// <param name="existing">Collection that will be changed</param>
        /// <param name="data">New data to append</param>
        /// <param name="policy">How to manage key duplicates</param>
        /// \ingroup_disabled ace_ext_collections_highlight
        public static void AppendData(this PropertyCollection existing, PropertyCollection data, existingDataMode policy, Boolean showException = true)
        {
            PropertyCollection temp = new PropertyCollection();

            if ((data == null) && showException)
            {
                throw new ArgumentNullException("data", "AppendData failed because data is null");
                return;
            }
            if (data == null)
            {
                return;
            }

            switch (policy)
            {
            case existingDataMode.clearExisting:
                existing.Clear();
                existing.AddRange(data);
                break;

            case existingDataMode.filterAndLeaveExisting:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        temp.Add(input.Key, existing[input.Key]);
                    }
                }
                existing.Clear();
                existing.AddRange(temp);
                break;

            case existingDataMode.filterNewOverwriteExisting:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        existing[input.Key] = input.Value;
                    }
                }
                break;

            case existingDataMode.leaveExisting:
                existing.AddRange(data, true);
                break;

            case existingDataMode.overwriteExistingIfEmptyOrNull:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        if (imbSciStringExtensions.isNullOrEmptyString(existing[input.Key].toStringSafe("")))
                        {
                            existing[input.Key] = input.Value;
                        }
                    }
                    else
                    {
                        existing.Add(input.Key, input.Value);
                    }
                }
                break;

            case existingDataMode.overwriteExisting:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        existing[input.Key] = input.Value;
                    }
                    else
                    {
                        existing.Add(input.Key, input.Value);
                    }
                }
                break;

            case existingDataMode.sumWithExisting:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        Object result = existing[input.Key].sumValues(input.Value);
                    }
                    else
                    {
                        existing.Add(input.Key, input.Value);
                    }
                }
                break;

            default:
                throw new NotImplementedException(imbStringFormats.toStringSafe(policy) + " called but not implemented");
                break;
            }
        }