/// <summary> /// Returns <see langword = "true" /> if there is a subscriber matching /// <see cref = "T:Senticode.Xamarin.Tools.Core.Events.SubscriptionToken" />. /// </summary> /// <param name = "token"> /// The <see cref = "T:Senticode.Xamarin.Tools.Core.Events.SubscriptionToken" /> returned by /// <see cref = "T:Senticode.Xamarin.Tools.Core.Events.EventBase" /> while subscribing to the event. /// </param> /// <returns> /// <see langword = "true" /> if there is a <see cref = "T:Senticode.Xamarin.Tools.Core.Events.SubscriptionToken" /> that /// matches; otherwise <see langword = "false" />. /// </returns> public virtual bool Contains(SubscriptionToken token) { var subscriptions = Subscriptions; var lockTaken = false; try { Monitor.Enter(subscriptions, ref lockTaken); return(Subscriptions.FirstOrDefault(evt => evt.SubscriptionToken == token) != null); } finally { if (lockTaken) { Monitor.Exit(subscriptions); } } }
/// <summary> /// Removes the subscriber matching the <see cref = "T:Senticode.Xamarin.Tools.Core.Events.SubscriptionToken" />. /// </summary> /// <param name = "token"> /// The <see cref = "T:Senticode.Xamarin.Tools.Core.Events.SubscriptionToken" /> returned by /// <see cref = "T:Senticode.Xamarin.Tools.Core.Events.EventBase" /> while subscribing to the event. /// </param> public virtual void Unsubscribe(SubscriptionToken token) { var subscriptions = Subscriptions; var lockTaken = false; try { Monitor.Enter(subscriptions, ref lockTaken); var eventSubscription = Subscriptions.FirstOrDefault(evt => evt.SubscriptionToken == token); if (eventSubscription == null) { return; } Subscriptions.Remove(eventSubscription); } finally { if (lockTaken) { Monitor.Exit(subscriptions); } } }