One special dictionary

由于项目一个功能需要,可以将关键字的值叠加加来,最终可以获取对这些关键字都做了些什么操作。

Generic Programming is very powerful.

 1     /// <summary>
 2     /// 
 3     /// </summary>
 4     /// <typeparam name="TKey"></typeparam>
 5     public class CXSpecialDictionary<TKey> : Dictionary<TKey, string>
 6     {
 7         /// <summary>
 8         /// 
 9         /// </summary>
10         /// <param name="key"></param>
11         /// <returns></returns>
12         public new string this[TKey key]
13         {
14             get { if (base.ContainsKey(key)) return base[key]; return ""; }
15             set { if (base.ContainsKey(key)) base[key] = base[key] + "\r\n" + value; else base.Add(key, value); }
16         }
17         /// <summary>
18         /// 
19         /// </summary>
20         /// <param name="key"></param>
21         /// <param name="value"></param>
22         public new void Add(TKey key, string value)
23         {
24             if (base.ContainsKey(key))
25             {
26                 base[key] = base[key] + "\r\n" + value;
27                 return;
28             }
29             base.Add(key, value);
30         }
31 
32     }

 

posted @ 2013-07-26 10:57  iDragon  阅读(209)  评论(0编辑  收藏  举报