예제 #1
0
 /// <summary>
 /// Indexer
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public ICollection <TValue> this[TKey key] {
     get { return(InnerMap.GetOrAdd(key, k => new List <TValue>())); }
     set {
         if (value != null)
         {
             Add(key, value.ToArray <TValue>());
         }
         else
         {
             this[key].Clear();
         }
     }
 }
예제 #2
0
        /// <summary>
        /// 해당 키에 값이 없다면 값을 넣고, 반환합니다.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="valueFactory"></param>
        /// <returns></returns>
        public ICollection <TValue> GetOrAdd(TKey key, Func <TKey, ICollection <TValue> > valueFactory)
        {
            valueFactory.ShouldNotBeNull("valueFactory");

            if (ContainsKey(key))
            {
                var values = this[key];
                foreach (var value in valueFactory(key))
                {
                    values.Add(value);
                }

                return(values);
            }

            return(InnerMap.GetOrAdd(key, valueFactory));
        }
예제 #3
0
 public ISet <TValue> GetOrAdd(TKey key, ISet <TValue> values)
 {
     return(InnerMap.GetOrAdd(key, k => values));
 }
예제 #4
0
 public ISet <TValue> GetOrAdd(TKey key, Func <TKey, ISet <TValue> > valuesFactory)
 {
     return(InnerMap.GetOrAdd(key, valuesFactory));
 }