/* * Copyright (C) 2013 FooProject * * 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 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FooEditEngine { class ResourceManager : Dictionary { /// /// 任意のキーに関連付けられている値を取得・設定する /// /// キー /// 関連付けられている値 public new TValue this[TKey key] { get { return base[key]; } set { if (value is IDisposable && base.ContainsKey(key)) ((IDisposable)base[key]).Dispose(); base[key] = value; } } /// /// 任意のキーに関連づけられてる値を削除する /// /// キー /// IDispseableを継承している場合、Dispose()が呼び出されます public new bool Remove(TKey key) { TValue value; bool result = base.TryGetValue(key, out value); if (value is IDisposable) ((IDisposable)value).Dispose(); if (result) base.Remove(key); return result; } /// /// すべて削除する /// /// IDispseableを継承している場合、Dispose()が呼び出されます public new void Clear() { if (this.Count == 0) return; TValue first = this.Values.First(); if (first is IDisposable) { foreach (IDisposable v in this.Values) v.Dispose(); } base.Clear(); } } }