PermTempAction.3.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. namespace kt
  4. {
  5. public class PermTempAction<T0, T1>
  6. {
  7. public void Add(Action<T0, T1> callback, bool is_temp = false)
  8. {
  9. if (callback != null)
  10. {
  11. this.CallBackFlagDic[callback] = is_temp;
  12. }
  13. }
  14. public void Remove(Action<T0, T1> callback)
  15. {
  16. if (callback != null)
  17. {
  18. this.CallBackFlagDic.Remove(callback);
  19. }
  20. }
  21. public void Clear()
  22. {
  23. this.CallBackFlagDic.Clear();
  24. }
  25. public void Invoke(T0 t0, T1 t1)
  26. {
  27. List<Action<T0, T1>> list = new List<Action<T0, T1>>();
  28. foreach (KeyValuePair<Action<T0, T1>, bool> keyValuePair in this.CallBackFlagDic)
  29. {
  30. Action<T0, T1> key = keyValuePair.Key;
  31. if (keyValuePair.Value || key == null)
  32. {
  33. list.Add(key);
  34. }
  35. if (key != null)
  36. {
  37. key(t0, t1);
  38. }
  39. }
  40. for (int i = 0; i < list.Count; i++)
  41. {
  42. this.CallBackFlagDic.Remove(list[i]);
  43. }
  44. }
  45. private Dictionary<Action<T0, T1>, bool> CallBackFlagDic = new Dictionary<Action<T0, T1>, bool>();
  46. }
  47. }