コード例 #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));
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
        }