using System; using System.Collections.Generic; using System.Linq; namespace IFramework.MVVM { /// /// MVVM 模块 /// public class MVVMGroups : Unit { /// /// 注销 /// protected override void OnDispose() { var em = _groupmap.Values.ToList(); em.ForEach((e) => { e.Dispose(); }); _groupmap = null; } private Dictionary _groupmap=new Dictionary(); /// /// 查找组 /// /// /// public MVVMGroup FindGroup(string name) { MVVMGroup _group; _groupmap.TryGetValue(name, out _group); return _group; } /// /// 注册一个 MVVM /// public void AddGroup(MVVMGroup group) { MVVMGroup _group = FindGroup(group.name); if (_group != null) throw new Exception("Have Add Group " + group.name); else { _groupmap.Add(group.name, group); } } /// /// 移除组 /// /// public void RemoveGroup(string name) { MVVMGroup _group = FindGroup(name); if (_group == null) throw new Exception("Have not Add Group " + name); else { _groupmap.Remove(name); } } /// /// 移除组 /// /// public void RemoveGroup(MVVMGroup group) { RemoveGroup(group.name); } } }