Beispiel #1
0
 private DictionaryTree <TKey, TValue> Underlay(DictionaryTree <TKey, TValue> overridingInstance)
 {
     lock (_syncRoot)
     {
         if (overridingInstance == null)
         {
             overridingInstance = new DictionaryTree <TKey, TValue>();
         }
         foreach (var pair in _localEntries)
         {
             if (!overridingInstance.LocalEntries.ContainsKey(pair.Key))
             {
                 overridingInstance.LocalEntries.Add(pair.Key, pair.Value);
             }
         }
         foreach (var pair in LocalDefaults)
         {
             if (!overridingInstance.LocalDefaults.ContainsKey(pair.Key))
             {
                 overridingInstance.LocalDefaults.Add(pair.Key, pair.Value);
             }
         }
         return(overridingInstance);
     }
 }
Beispiel #2
0
        /// <summary>
        /// This returns all entries found in Defaults, Parents, and the Primary dictionary.
        /// Defaults are entered first, then each parent (from oldest to newest) adds or updates entries,
        /// and finally the Primary entries are enumerated to update whatever already exists, adding
        /// whatever has not yet been entered. This ensures that only the final values will appear for
        /// each unique key.
        /// </summary>
        public DictionaryTree <TKey, TValue> Flatten(DictionaryTree <TKey, TValue> overridingInstance)
        {
            lock (_syncRoot)
            {
                if (overridingInstance == null)
                {
                    overridingInstance = new DictionaryTree <TKey, TValue>();
                }
                overridingInstance = Underlay(overridingInstance);
                // add missing entries from each of the parents, newest to oldest, flattening each in turn
                for (var x = Parents.Count - 1; x >= 0; x--)
                {
                    // parents are only adding entries for keys that don't yet exist
                    overridingInstance = Parents[x].Flatten(overridingInstance);
                }

                return(overridingInstance);
            }
        }