Example #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));
        }
Example #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));
        }
Example #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());
        }
Example #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));
        }
Example #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));
            }
        }