示例#1
0
        public Root.Code.Models.E01D.Core.Collections.Generic.Dictionary <TKey, TValue> Create <TKey, TValue>(Models.E01D.Core.Collections.Generic.Dictionary <TKey, TValue> existingDictionary, IEqualityComparer <TKey> comparer)
        {
            Root.Code.Models.E01D.Core.Collections.Generic.Dictionary <TKey, TValue> dictionaryNew;

            if (existingDictionary != null)
            {
                dictionaryNew = Create <TKey, TValue>(existingDictionary.Count, comparer);
            }
            else
            {
                dictionaryNew = Create <TKey, TValue>(comparer);
            }

            if (existingDictionary == null)
            {
                throw XExceptions.Argument.IsNull(nameof(existingDictionary));
            }

            // It is likely that the passed-in dictionary is Dictionary<TKey,TValue>. When this is the case,
            // avoid the enumerator allocation and overhead by looping through the entries array directly.
            // We only do this when dictionary is Dictionary<TKey,TValue> and not a subclass, to maintain
            // back-compat with subclasses that may have overridden the enumerator behavior.
            if (existingDictionary.GetType() == typeof(Root.Code.Models.E01D.Core.Collections.Generic.Dictionary <TKey, TValue>))
            {
                var d = (Root.Code.Models.E01D.Core.Collections.Generic.Dictionary <TKey, TValue>)existingDictionary;

                var count = d.Count;

                var entries = d.Entries;

                for (var i = 0; i < count; i++)
                {
                    if (entries[i].HashCode >= 0)
                    {
                        Add(dictionaryNew, entries[i].Key, entries[i].Value);
                    }
                }

                return(dictionaryNew);
            }

            throw new System.NotImplementedException();
            //foreach (var pair in existingDictionary)
            //{
            //    Add(dictionaryNew, pair.Key, pair.Value);
            //}

            //return dictionaryNew;
        }
示例#2
0
 public Root.Code.Models.E01D.Core.Collections.Generic.Dictionary <TKey, TValue> Create <TKey, TValue>(Models.E01D.Core.Collections.Generic.Dictionary <TKey, TValue> existingDictionary)
 {
     return(Create(existingDictionary, null));
 }