예제 #1
0
 public static int Count <T>(WeakList <T> list) where T : class
 {
     if (list != null)
     {
         return(list.Count);
     }
     return(0);
 }
예제 #2
0
 public static bool IsValid <T>(WeakList <T> list, Func <T, bool> callback) where T : class
 {
     if (list != null)
     {
         return(list.UntilFalse(callback));
     }
     return(true);
 }
예제 #3
0
 public static bool Remove <T>(WeakList <T> list, T element) where T : class
 {
     if (element == null)
     {
         return(false);
     }
     if (list != null)
     {
         return(list.Remove(element));
     }
     return(false);
 }
예제 #4
0
 public static bool Add <T>(ref WeakList <T> list, T element) where T : class
 {
     if (element == null)
     {
         return(false);
     }
     if (list == null)
     {
         list = new WeakList <T>();
     }
     return(list.AddElement(element));
 }
예제 #5
0
 public int GetSubCount(TPub pub)
 {
     if (_InstanceSubscribers != null)
     {
         int             pubHash = pub.GetHashCode();
         WeakList <TSub> subs    = null;
         if (_InstanceSubscribers.TryGetValue(pubHash, out subs))
         {
             return(subs.Count);
         }
     }
     return(0);
 }
예제 #6
0
        public bool RemoveSub(TPub pub, TSub sub)
        {
            if (_InstanceSubscribers == null)
            {
                return(false);
            }
            int             pubHash = pub.GetHashCode();
            WeakList <TSub> subs    = null;

            if (!_InstanceSubscribers.TryGetValue(pubHash, out subs))
            {
                return(false);
            }
            return(subs.Remove(sub));
        }
예제 #7
0
        public bool AddSub(TPub pub, TSub sub)
        {
            if (_InstanceSubscribers == null)
            {
                _InstanceSubscribers = new Dictionary <int, WeakList <TSub> >();
            }
            int             pubHash = pub.GetHashCode();
            WeakList <TSub> subs    = null;

            if (!_InstanceSubscribers.TryGetValue(pubHash, out subs))
            {
                subs = new WeakList <TSub>();
                _InstanceSubscribers[pubHash] = subs;
            }
            return(subs.AddElement(sub));
        }
예제 #8
0
        public void Publish(TPub pub, Action <TSub> callback)
        {
            if (_InstanceSubscribers != null)
            {
                int             pubHash = pub.GetHashCode();
                WeakList <TSub> subs    = null;
                if (_InstanceSubscribers.TryGetValue(pubHash, out subs))
                {
                    subs.ForEach(callback);

                    if (subs.Count == 0)
                    {
                        _InstanceSubscribers.Remove(pubHash);
                    }
                }
            }
            WeakListHelper.Notify(_ClassSubscribers, callback);
        }
예제 #9
0
 public static void Notify <T>(WeakList <T> list, Action <T> callback) where T : class
 {
     ForEach(list, callback);
 }