12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- using System.Collections.Generic;
- namespace kt
- {
- public class PermTempAction<T0, T1>
- {
- public void Add(Action<T0, T1> callback, bool is_temp = false)
- {
- if (callback != null)
- {
- this.CallBackFlagDic[callback] = is_temp;
- }
- }
- public void Remove(Action<T0, T1> callback)
- {
- if (callback != null)
- {
- this.CallBackFlagDic.Remove(callback);
- }
- }
- public void Clear()
- {
- this.CallBackFlagDic.Clear();
- }
- public void Invoke(T0 t0, T1 t1)
- {
- List<Action<T0, T1>> list = new List<Action<T0, T1>>();
- foreach (KeyValuePair<Action<T0, T1>, bool> keyValuePair in this.CallBackFlagDic)
- {
- Action<T0, T1> key = keyValuePair.Key;
- if (keyValuePair.Value || key == null)
- {
- list.Add(key);
- }
- if (key != null)
- {
- key(t0, t1);
- }
- }
- for (int i = 0; i < list.Count; i++)
- {
- this.CallBackFlagDic.Remove(list[i]);
- }
- }
- private Dictionary<Action<T0, T1>, bool> CallBackFlagDic = new Dictionary<Action<T0, T1>, bool>();
- }
- }
|