Exemplo n.º 1
0
        /// <summary>
        /// Merge hash tables.
        /// </summary>
        /// <param name="extra">Hash table to merge with original one.</param>
        /// <returns>Merged hash table.</returns>
        public THashtable Merge(THashtable extra)
        {
            if (extra == null)
            {
                return(this);
            }

            var output = Create();

            TEnumerator keys1 = new TEnumerator(this.Keys.GetEnumerator());

            while (keys1.MoveNext())
            {
                String key1 = (String)keys1.GetCurrent();
                output[key1] = this[key1];
            }

            TEnumerator keys2 = new TEnumerator(extra.Keys.GetEnumerator());

            while (keys2.MoveNext())
            {
                String key2 = (String)keys2.GetCurrent();
                output[key2] = extra[key2];
            }
            return(output);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Replace "keys by values" in a string.
        /// </summary>
        /// <param name="template">Input template.</param>
        /// <param name="hash">Set of key/value pairs.</param>
        /// <returns>Resulting string.</returns>
        public static String ReplaceInTemplate(String template, THashtable hash)
        {
            var keys = new TEnumerator(hash.Keys.GetEnumerator());

            while (keys.MoveNext())
            {
                var key = STR(keys.GetCurrent());
                if (template.IndexOf(key) != -1)
                {
                    template = template.Replace(key, STR(hash[key]));
                }
            }
            return(template);
        }