示例#1
0
 /// <summary>
 /// Unregisters a message recipient for a given type of messages, for
 /// a given action and a given token. Other message types will still be transmitted to the
 /// recipient (if it registered for them previously). Other actions that have
 /// been registered for the message type TMessage, for the given recipient and other tokens (if
 /// available) will also remain available.
 /// </summary>
 /// <typeparam name="TMessage">The type of messages that the recipient wants
 /// to unregister from.</typeparam>
 /// <param name="recipient">The recipient that must be unregistered.</param>
 /// <param name="token">The token for which the recipient must be unregistered.</param>
 /// <param name="action">The action that must be unregistered for
 /// the recipient and for the message type TMessage.</param>
 public virtual void Unregister <TMessage>(object recipient, object token, Action <TMessage> action)
 {
     Messager.UnregisterFromLists <TMessage>(recipient, token, action, this._recipientsStrictAction);
     Messager.UnregisterFromLists <TMessage>(recipient, token, action, this._recipientsOfSubclassesAction);
     this.Cleanup();
 }
示例#2
0
 private void Cleanup()
 {
     Messager.CleanupList(this._recipientsOfSubclassesAction);
     Messager.CleanupList(this._recipientsStrictAction);
 }
示例#3
0
 /// <summary>
 /// Unregisters a messager recipient completely. After this method
 /// is executed, the recipient will not receive any messages anymore.
 /// </summary>
 /// <param name="recipient">The recipient that must be unregistered.</param>
 public virtual void Unregister(object recipient)
 {
     Messager.UnregisterFromLists(recipient, this._recipientsOfSubclassesAction);
     Messager.UnregisterFromLists(recipient, this._recipientsStrictAction);
 }
示例#4
0
        private static void SendToList <TMessage>(TMessage message, IEnumerable <Messager.WeakActionAndToken> list, Type messageTargetType, object token)
        {
            bool flag;

            if (list != null)
            {
                List <Messager.WeakActionAndToken> weakActionAndTokens = list.Take <Messager.WeakActionAndToken>(list.Count <Messager.WeakActionAndToken>()).ToList <Messager.WeakActionAndToken>();
                foreach (Messager.WeakActionAndToken weakActionAndToken in weakActionAndTokens)
                {
                    IExecuteWithObject action = weakActionAndToken.Action as IExecuteWithObject;
                    if (action == null || !weakActionAndToken.Action.IsAlive || weakActionAndToken.Action.Target == null || !(messageTargetType == null) && !(weakActionAndToken.Action.Target.GetType() == messageTargetType) && !Messager.Implements(weakActionAndToken.Action.Target.GetType(), messageTargetType))
                    {
                        flag = false;
                    }
                    else if (weakActionAndToken.Token != null || token != null)
                    {
                        flag = (weakActionAndToken.Token == null ? false : weakActionAndToken.Token.Equals(token));
                    }
                    else
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        action.ExecuteWithObject(message);
                    }
                }
            }
        }
示例#5
0
 /// <summary>
 /// Sets the Messenger's default (static) instance to null.
 /// </summary>
 public static void Reset()
 {
     Messager._defaultInstance = null;
 }
示例#6
0
 /// <summary>
 /// Provides a way to override the Messenger.Default instance with
 /// a custom instance, for example for unit testing purposes.
 /// </summary>
 /// <param name="newMessenger">The instance that will be used as Messenger.Default.</param>
 public static void OverrideDefault(Messager newMessenger)
 {
     Messager._defaultInstance = newMessenger;
 }