public bool Equals(HashableWeakRef <T> aObj) { if (_weakReference != null) { return(this.Target.Equals(aObj)); } return(false); }
public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator() { if (IsAutoClean) { Clean(); } foreach (KeyValuePair <object, TValue> entry in _refDict) { HashableWeakRef <TKey> weakKey = (HashableWeakRef <TKey>)entry.Key; yield return(new KeyValuePair <TKey, TValue>(weakKey.Target, entry.Value)); } }
private bool Clean(HashableWeakRef <TKey> aKey) { bool success = false; if (!aKey.IsAlive) { if (_refDict[aKey] is IDisposable) { (_refDict[aKey] as IDisposable).Dispose(); } _refDict.Remove(aKey); success = true; } return(success); }
public bool Clean() { List <HashableWeakRef <TKey> > weakKeyListToRemove = new List <HashableWeakRef <TKey> >(); bool success = false; foreach (KeyValuePair <object, TValue> entry in _refDict) { HashableWeakRef <TKey> weakKey = (HashableWeakRef <TKey>)entry.Key; if (!weakKey.IsAlive) { weakKeyListToRemove.Add(weakKey); } } for (int i = 0; i < weakKeyListToRemove.Count; i++) { Clean(weakKeyListToRemove[i]); success = true; } return(success); }
/********************************************************** * Public Methods *********************************************************/ public void Add(TKey aKey, TValue aValue) { HashableWeakRef <TKey> weakKey = new HashableWeakRef <TKey>(aKey); _refDict.Add(weakKey, aValue); }