MVVMGroups.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace IFramework.MVVM
  5. {
  6. /// <summary>
  7. /// MVVM 模块
  8. /// </summary>
  9. public class MVVMGroups : Unit
  10. {
  11. /// <summary>
  12. /// 注销
  13. /// </summary>
  14. protected override void OnDispose()
  15. {
  16. var em = _groupmap.Values.ToList();
  17. em.ForEach((e) =>
  18. {
  19. e.Dispose();
  20. });
  21. _groupmap = null;
  22. }
  23. private Dictionary<string, MVVMGroup> _groupmap=new Dictionary<string, MVVMGroup>();
  24. /// <summary>
  25. /// 查找组
  26. /// </summary>
  27. /// <param name="name"></param>
  28. /// <returns></returns>
  29. public MVVMGroup FindGroup(string name)
  30. {
  31. MVVMGroup _group;
  32. _groupmap.TryGetValue(name, out _group);
  33. return _group;
  34. }
  35. /// <summary>
  36. /// 注册一个 MVVM
  37. /// </summary>
  38. public void AddGroup(MVVMGroup group)
  39. {
  40. MVVMGroup _group = FindGroup(group.name);
  41. if (_group != null)
  42. throw new Exception("Have Add Group " + group.name);
  43. else
  44. {
  45. _groupmap.Add(group.name, group);
  46. }
  47. }
  48. /// <summary>
  49. /// 移除组
  50. /// </summary>
  51. /// <param name="name"></param>
  52. public void RemoveGroup(string name)
  53. {
  54. MVVMGroup _group = FindGroup(name);
  55. if (_group == null)
  56. throw new Exception("Have not Add Group " + name);
  57. else
  58. {
  59. _groupmap.Remove(name);
  60. }
  61. }
  62. /// <summary>
  63. /// 移除组
  64. /// </summary>
  65. /// <param name="group"></param>
  66. public void RemoveGroup(MVVMGroup group)
  67. {
  68. RemoveGroup(group.name);
  69. }
  70. }
  71. }