public static int Count <T>(WeakList <T> list) where T : class { if (list != null) { return(list.Count); } return(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); }
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); }
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)); }
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); }
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)); }
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)); }
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); }
public static void Notify <T>(WeakList <T> list, Action <T> callback) where T : class { ForEach(list, callback); }