Пример #1
0
        private void SendToTargetOrType <TMessage>(TMessage message, Type messageTargetType, object token)
        {
            Type type = typeof(TMessage);

            if (this._recipientsOfSubclassesAction != null)
            {
                List <Type> list = this._recipientsOfSubclassesAction.Keys.Take <Type>(this._recipientsOfSubclassesAction.Count <KeyValuePair <Type, List <Messager.WeakActionAndToken> > >()).ToList <Type>();
                foreach (Type type1 in list)
                {
                    List <Messager.WeakActionAndToken> item = null;
                    if ((type == type1 || type.IsSubclassOf(type1) ? true : Messager.Implements(type, type1)))
                    {
                        item = this._recipientsOfSubclassesAction[type1];
                    }
                    Messager.SendToList <TMessage>(message, item, messageTargetType, token);
                }
            }
            if (this._recipientsStrictAction != null)
            {
                if (this._recipientsStrictAction.ContainsKey(type))
                {
                    List <Messager.WeakActionAndToken> weakActionAndTokens = this._recipientsStrictAction[type];
                    Messager.SendToList <TMessage>(message, weakActionAndTokens, messageTargetType, token);
                }
            }
            this.Cleanup();
        }
Пример #2
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);
                    }
                }
            }
        }