Exemplo n.º 1
0
        int IEqualityComparer <T> .GetHashCode(T obj)
        {
            WeakObject wobj = obj as WeakObject;

            if (wobj != null)
            {
                return(wobj.GetHashCode());
            }

            return((obj == null) ? 0 : RuntimeHelpers.GetHashCode(obj));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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));
            }
        }