ModelManager.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections.Generic;
  2. namespace WS
  3. {
  4. ///<summary>Model管理</summary>
  5. public class ModelManager : WSComponent
  6. {
  7. ///<summary>Model容器</summary>
  8. private List<Model> _AllModel = new List<Model>();
  9. ///<summary>注册/创建Model</summary>
  10. public T CreateModel<T>() where T : Model
  11. {
  12. T model = ComponentFactory.Create<T>();
  13. model.InitProperty();
  14. _AllModel.Add(model);
  15. return model;
  16. }
  17. ///<summary>删除Model</summary>
  18. public void Remove(Model model)
  19. {
  20. if (_AllModel.Contains(model))
  21. {
  22. model.Dispose();
  23. _AllModel.Remove(model);
  24. }
  25. }
  26. ///<summary>删除所有Model</summary>
  27. public void RemoveAll()
  28. {
  29. for (int i = 0; i < _AllModel.Count; i++)
  30. {
  31. _AllModel[i]?.Dispose();
  32. }
  33. _AllModel.Clear();
  34. }
  35. public override void Dispose()
  36. {
  37. base.Dispose();
  38. RemoveAll();
  39. }
  40. }
  41. }