Esempio n. 1
0
        internal bool Contains(object x, object y)
        {
            if (!IsReferencePair(x, y))
            {
                return(false);
            }

            using (var pair = ReferencePair.GetOrCreate(x, y))
            {
                return(this.pairs.Contains(pair));
            }
        }
Esempio n. 2
0
        public bool Equals(ReferencePair other)
        {
            Debug.Assert(!this.disposed, "this.disposed");
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(ReferenceEquals(this.X, other.X) && ReferenceEquals(this.Y, other.Y));
        }
Esempio n. 3
0
        internal bool?Add(object x, object y)
        {
            if (!IsReferencePair(x, y))
            {
                return(null);
            }

            var refCounted = ReferencePair.GetOrCreate(x, y);
            var added      = this.pairs.Add(refCounted);

            if (!added)
            {
                refCounted.Dispose();
            }

            return(added);
        }
Esempio n. 4
0
        internal static IRefCounted <TValue> GetOrAdd <TKey, TValue>(
            TKey x,
            TKey y,
            MemberSettings settings,
            ConditionalWeakTable <IRefCounted <ReferencePair>, TValue> .CreateValueCallback creator,
            out bool created)
            where TKey : class
            where TValue : class, IDisposable
        {
            var refCounted = ReferencePair.GetOrCreate(x, y);
            var value      = GetOrAdd(refCounted, settings, creator, out created);

            if (!created)
            {
                refCounted.Dispose();
            }

            return(value);
        }
Esempio n. 5
0
        public static IRefCounted <ReferencePair> GetOrCreate <T>(T x, T y)
            where T : class
        {
            var key = new ReferencePair(x, y);

            if (!Cache.GetOrAdd(key, p => p).TryRefCount(out var refcounted))
            {
                if (!Cache.TryAdd(key, key))
                {
                    throw Throw.ShouldNeverGetHereException("Adding created pair failed");
                }

                if (!key.TryRefCount(out refcounted))
                {
                    throw Throw.ShouldNeverGetHereException("Refcounting created pair failed");
                }
            }

            return(refcounted);
        }
Esempio n. 6
0
 private bool Equals(ReferencePair x, ReferencePair y)
 {
     return(ReferenceEquals(x.X, y.X) && ReferenceEquals(x.Y, y.Y));
 }