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
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
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
12 using System.Collections.Generic;
\r
16 namespace FooEditEngine
\r
18 class ResourceManager<TKey, TValue> : Dictionary<TKey, TValue>
\r
21 /// 任意のキーに関連付けられている値を取得・設定する
\r
23 /// <param name="key">キー</param>
\r
24 /// <returns>関連付けられている値</returns>
\r
25 public new TValue this[TKey key]
\r
33 if (value is IDisposable && base.ContainsKey(key))
\r
34 ((IDisposable)base[key]).Dispose();
\r
39 /// 任意のキーに関連づけられてる値を削除する
\r
41 /// <param name="key">キー</param>
\r
42 /// <returns>IDispseableを継承している場合、Dispose()が呼び出されます</returns>
\r
43 public new bool Remove(TKey key)
\r
46 bool result = base.TryGetValue(key, out value);
\r
47 if (value is IDisposable)
\r
48 ((IDisposable)value).Dispose();
\r
56 /// <remarks>IDispseableを継承している場合、Dispose()が呼び出されます</remarks>
\r
57 public new void Clear()
\r
59 if (this.Count == 0)
\r
61 TValue first = this.Values.First();
\r
62 if (first is IDisposable)
\r
64 foreach (IDisposable v in this.Values)
\r