Пример #1
0
 public override bool Equals(object obj)
 {
     return(obj switch {
         ComparableWeakReference <T> reference => this == reference,
         WeakReference <T> reference => this == reference,
         _ => false,
     });
Пример #2
0
 static bool Predicate(ComparableWeakReference <T> reference, Predicate <T> predicate)
 {
     if (reference.TryGetTarget(out T target))
     {
         return(predicate.Invoke(target));
     }
     return(false);
 }
Пример #3
0
        private static int Comparison(ComparableWeakReference <T> x, ComparableWeakReference <T> y, Comparison <T> comparer)
        {
            bool hasX = x.TryGetTarget(out T xTarget);
            bool hasY = y.TryGetTarget(out T yTarget);

            if (hasX != hasY)
            {
                return(hasX ? int.MaxValue : int.MinValue);
            }
            else if (!hasX)
            {
                return(0);
            }

            return(comparer.Invoke(xTarget, yTarget));
        }
Пример #4
0
 public bool Contains(ComparableWeakReference <T> item)
 {
     return(_List.Contains(item));
 }
Пример #5
0
 public int BinarySearch(ComparableWeakReference <T> item, IComparer <T> comparer)
 {
     return(_List.BinarySearch(item, new ReferenceComparer(comparer)));
 }
Пример #6
0
 int IComparer <ComparableWeakReference <T> > .Compare(ComparableWeakReference <T> x, ComparableWeakReference <T> y)
 {
     return(Comparison(x, y, Comparer.Compare));
 }
Пример #7
0
 public int BinarySearch(ComparableWeakReference <T> item)
 {
     return(_List.BinarySearch(item));
 }
Пример #8
0
 public void Add(ComparableWeakReference <T> item)
 {
     _List.Add(item);
 }
Пример #9
0
 public static bool Equals(object objA, ComparableWeakReference <T> objB)
 {
     return(objB.Equals(objA));
 }
Пример #10
0
 public static bool Equals(WeakReference <T> objA, ComparableWeakReference <T> objB)
 {
     return(objA == objB);
 }
Пример #11
0
 public bool Equals(ComparableWeakReference <T> obj)
 {
     return(this == obj);
 }