Пример #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));
        }
Пример #2
0
        int IEqualityComparer <T> .GetHashCode(T obj)
        {
            WeakObject wobj = obj as WeakObject;

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

            return((obj == null) ? 0 : ReferenceEqualityComparer <object> .Instance.GetHashCode(obj));
        }
Пример #3
0
        int IEqualityComparer <T> .GetHashCode(T obj)
        {
            WeakObject <T> wobj = obj as WeakObject <T>;

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

            return((obj == null) ? 0 : obj.GetHashCode());
        }
Пример #4
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));
        }
Пример #5
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));
            }
        }