예제 #1
0
        public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator()
        {
            SingleDependency single = _data as SingleDependency;

            if (single != null)
            {
                yield return(new KeyValuePair <TKey, TValue>(single.Key, single.Value));
            }

            AnalysisDictionary <TKey, TValue> dict = _data as AnalysisDictionary <TKey, TValue>;

            if (dict != null)
            {
                foreach (var keyValue in dict)
                {
                    yield return(keyValue);
                }
            }
        }
예제 #2
0
        public TValue this[TKey key] {
            get {
                TValue res;
                if (TryGetValue(key, out res))
                {
                    return(res);
                }

                throw new KeyNotFoundException();
            }
            set {
                if (_data == null)
                {
                    _data = new SingleDependency(key, value);
                    return;
                }

                var single = _data as SingleDependency;
                if (single != null)
                {
                    if (EqualityComparer <TKey> .Default.Equals(single.Key, key))
                    {
                        single.Value = value;
                        return;
                    }

                    var data = new AnalysisDictionary <TKey, TValue>();
                    data[single.Key] = single.Value;
                    data[key]        = value;
                    _data            = data;
                    return;
                }

                var dict = _data as AnalysisDictionary <TKey, TValue>;
                if (dict == null)
                {
                    _data = dict = new AnalysisDictionary <TKey, TValue>();
                }
                dict[key] = value;
            }
        }
예제 #3
0
 internal AnalysisDictionaryEnumerator(AnalysisDictionary <TKey, TValue> dict)
 {
     _buckets   = dict._buckets;
     _curValue  = default(KeyValuePair <TKey, TValue>);
     _curBucket = 0;
 }