Exemple #1
0
    public void Subscribe <T>(MediatorCallback <T> callback) where T : ICommand
    {
        if (callback == null)
        {
            throw new System.ArgumentNullException("callback");
        }
        var tp = typeof(T);

        if (_subscribers.ContainsKey(tp))
        {
            _subscribers[tp] = System.Delegate.Combine(_subscribers[tp], callback);
        }
        else
        {
            _subscribers.Add(tp, callback);
        }
    }
 public static void AddSubscribe <T>(MediatorCallback <T> _message) where T : BaseMessage
 {
     if (mediator)
     {
         if (_message == null)
         {
             return;
         }
         var t = typeof(T);
         if (mediator.subscribers.ContainsKey(t))
         {
             mediator.subscribers[t] = Delegate.Combine(mediator.subscribers[t], _message);
         }
         else
         {
             mediator.subscribers.Add(t, _message);
         }
     }
 }
Exemple #3
0
    public void DeleteSubscriber <T>(MediatorCallback <T> callback) where T : ICommand
    {
        if (callback == null)
        {
            throw new System.ArgumentNullException("callback");
        }
        var tp = typeof(T);

        if (_subscribers.ContainsKey(tp))
        {
            var d = _subscribers[tp];
            d = System.Delegate.Remove(d, callback);
            if (d == null)
            {
                _subscribers.Remove(tp);
            }
            else
            {
                _subscribers[tp] = d;
            }
        }
    }
 public static void RemoveSubscribe <T>(MediatorCallback <T> _message) where T : BaseMessage
 {
     if (mediator)
     {
         if (_message == null)
         {
             return;
         }
         var t = typeof(T);
         if (mediator.subscribers.ContainsKey(t))
         {
             var temp = mediator.subscribers[t];
             temp = System.Delegate.Remove(temp, _message);
             if (temp == null)
             {
                 mediator.subscribers.Remove(t);
             }
             else
             {
                 mediator.subscribers[t] = temp;
             }
         }
     }
 }