Ejemplo n.º 1
0
 /// <summary>
 /// 移除通知名称 下面的所有通知
 /// </summary>
 /// <param name="notifyName">通知名称</param>
 /// <param name="action">动作</param>
 public void RemoveObserver(string notifyName, BlankActionForObject action)
 {
     if (m_dictionary.ContainsKey(notifyName))
     {
         // 移除values 中的数据
         NotificationModel notificationModel = m_dictionary[notifyName];
         if (notificationModel != null)
         {
             if (notificationModel.observerList != null && notificationModel.observerList.Remove(action))
             {
                 if (notificationModel.observerList.Count <= 0)
                 {
                     // 当values 的长度为0 时 移除整个通知
                     m_dictionary.Remove(notifyName);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 添加单个通知监听
 /// </summary>
 /// <param name="notifyName">通知名称</param>
 /// <param name="sender"></param>
 /// <param name="action">执行函数回调</param>
 public void AddObserver(string notifyName, string sender, BlankActionForObject action)
 {
     // Log.W(sender, "SENDER");
     if (m_dictionary.ContainsKey(notifyName))
     {
         NotificationModel notificationModel = m_dictionary[notifyName];
         if (notificationModel != null)
         {
             notificationModel.filterName = sender;
             notificationModel.notifyName = notifyName;
             List <BlankActionForObject> list = notificationModel.observerList;
             if (list != null && list.Count > 0)
             {
                 for (int i = 0; i < list.Count; i++)
                 {
                     if (list[i].Equals(action))
                     {
                         list[i] = action;
                         return;
                     }
                 }
                 list.Add(action);
             }
             else
             {
                 m_dictionary[notifyName] = notificationModel;
             }
         }
     }
     else
     {
         m_dictionary.Add(notifyName, new NotificationModel {
             notifyName = notifyName, observerList = new List <BlankActionForObject> {
                 action
             }, filterName = sender
         });
     }
 }