/// <summary> /// Unlinks a custom delegate from a message that may be breadcasted via a Publisher /// </summary> /// <param name="message">The message to unsubscribe from (case sensitive)</param> /// <param name="callback">The delegate to be unlinked from the broadcast message</param> public void Unsubscribe(string message, Callback.Callback callback) { // First, remove the subscription from the internal records Unsubscribe(ref localSubscriptions, message, callback); // Then, remove the subcription from the public records Unsubscribe(ref instance.subscriptions, message, callback); }
/// <summary> /// Links a custom delegate to a message that may be breadcasted via a Publisher /// </summary> /// <param name="message">The message to subscribe to (case sensitive)</param> /// <param name="callback">The delegate to be linked to the broadcast message</param> public void Subscribe(string message, Callback.Callback callback) { // First, adds the subscription to the internaal records Subscribe(ref localSubscriptions, message, callback); // Then, adds the subcription to the public records Subscribe(ref instance.subscriptions, message, callback); }
/// <summary> /// Unlinks a custom delegate from a message in a SPECIFIC subscription dictionary /// </summary> /// <param name="container">Refrence to the dictionary of subscriptions we want to modify</param> /// <param name="message">The message to unsubscribe from (case sensitive)</param> /// <param name="callback">The delegate to be removed from the broadcast message</param> public void Unsubscribe(ref System.Collections.Generic.Dictionary <string, Callback.Callback> container, string message, Callback.Callback callback) { // Temporary delegate container for modifying subscription delegates Callback.Callback cb; // Check to see if there is a subscription to this message if (container.TryGetValue(message, out cb)) { /// If the subscription does already exist, /// then cb is populated with all associated delegates. /// Otherwise nothing will happen // Remove the selected delegate from the callback cb -= callback; // Check the modified cb to see if there are any delegates left if (cb == null) { // If tere is not, then remove the subscription completely container.Remove(message); } else { // If there are some left, reset the callback to the now lesser cb container[message] = cb; } } }
/// <summary> /// Links a custom delegate to a message that may be breadcasted via a Publisher /// </summary> /// <param name="message">The message to subscribe to (case sensitive)</param> /// <param name="callback">The delegate to be linked to the broadcast message</param> public void Subscribe(string message, Callback.Callback callback, bool acceptStaleMessages = false) { // First, adds the subscription to the internal records Subscribe(ref localSubscriptions, message, callback); // Then, adds the subscription to the public records Subscribe(ref instance.subscriptions, message, callback); if (acceptStaleMessages && instance.heldMessages.Contains(message)) { instance.heldMessages.Remove(message); callback.Invoke(null); } }
/// <summary> /// Links a custom delegate to a message in a SPECIFIC subscription dictionary /// </summary> /// <param name="container">Refrence to the dictionary of subscriptions we want to modify</param> /// <param name="message">The message to subscribe to (case sensitive)</param> /// <param name="callback">The delegate to be linked to the broadcast message</param> private void Subscribe(ref System.Collections.Generic.Dictionary <string, Callback.Callback> container, string message, Callback.Callback callback) { // Temporary delegate container for modifying subscription delegates Callback.Callback cb; // Check to see if there is not already a subscription to this message if (!container.TryGetValue(message, out cb)) { // If there is not, then make one with the message and currently empty callback delegate container.Add(message, cb); } /// If the subscription does already exist, /// then cb is populated with all associated delegates, /// if it does not, cb is empty. // Add the delegate to cb (new or populated) cb += callback; // Set the delegate linked to the message to cb container[message] = cb; }