int IEqualityComparer <T> .GetHashCode(T obj) { WeakObject wobj = obj as WeakObject; if (wobj != null) { return(wobj.GetHashCode()); } return((obj == null) ? 0 : RuntimeHelpers.GetHashCode(obj)); }
bool IEqualityComparer <T> .Equals(T x, T y) { WeakObject wx = x as WeakObject; if (wx != null) { x = (T)wx.Target; } WeakObject wy = y as WeakObject; if (wy != null) { y = (T)wy.Target; } return(Object.Equals(x, y)); }
public T GetObjectFromId(int id) { object ret; if (_dict.TryGetValue(id, out ret)) { WeakObject weakObj = ret as WeakObject; if (weakObj != null) { return((T)weakObj.Target); } if (ret is T) { return((T)ret); } throw new InvalidOperationException("Unexpected dictionary content: type " + ret.GetType()); } else { return(default(T)); } }