OSDN Git Service

起動時にキャレットを表示させるようにした。これにともないタイマー起動タイミングを変更した
[fooeditengine/FooEditEngine.git] / Common / ResourceManager.cs
1 /*\r
2  * Copyright (C) 2013 FooProject\r
3  * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by\r
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\r
5 \r
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of \r
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
8 \r
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
10  */\r
11 using System;\r
12 using System.Collections.Generic;\r
13 using System.Linq;\r
14 using System.Text;\r
15 \r
16 namespace FooEditEngine\r
17 {\r
18     class ResourceManager<TKey, TValue> : Dictionary<TKey, TValue>\r
19     {\r
20         /// <summary>\r
21         /// 任意のキーに関連付けられている値を取得・設定する\r
22         /// </summary>\r
23         /// <param name="key">キー</param>\r
24         /// <returns>関連付けられている値</returns>\r
25         public new TValue this[TKey key]\r
26         {\r
27             get\r
28             {\r
29                 return base[key];\r
30             }\r
31             set\r
32             {\r
33                 if (value is IDisposable && base.ContainsKey(key))\r
34                     ((IDisposable)base[key]).Dispose();\r
35                 base[key] = value;\r
36             }\r
37         }\r
38         /// <summary>\r
39         /// 任意のキーに関連づけられてる値を削除する\r
40         /// </summary>\r
41         /// <param name="key">キー</param>\r
42         /// <returns>IDispseableを継承している場合、Dispose()が呼び出されます</returns>\r
43         public new bool Remove(TKey key)\r
44         {\r
45             TValue value;\r
46             bool result = base.TryGetValue(key, out value);\r
47             if (value is IDisposable)\r
48                 ((IDisposable)value).Dispose();\r
49             if (result)\r
50                 base.Remove(key);\r
51             return result;\r
52         }\r
53         /// <summary>\r
54         /// すべて削除する\r
55         /// </summary>\r
56         /// <remarks>IDispseableを継承している場合、Dispose()が呼び出されます</remarks>\r
57         public new void Clear()\r
58         {\r
59             if (this.Count == 0)\r
60                 return;\r
61             TValue first = this.Values.First();\r
62             if (first is IDisposable)\r
63             {\r
64                 foreach (IDisposable v in this.Values)\r
65                     v.Dispose();\r
66             }\r
67             base.Clear();\r
68         }\r
69     }\r
70 }\r