public void CloseAll() { var enumerator = _opened.GetEnumerator(); while (enumerator.MoveNext()) { ViewItem item = enumerator.Current.Value; MediatorItem mediatorItem = _items[enumerator.Current.Key]; if (mediatorItem.closeMethod != null) { mediatorItem.closeMethod.Invoke(item.mediator, null); } _viewFactory.ReleaseView(item.view); } _opened.Clear(); }
public void Close(object viewKey) { if (!_items.ContainsKey(viewKey)) { throw new Exception(string.Format("{0} has not been mapped", viewKey)); } if (!_opened.ContainsKey(viewKey)) { throw new Exception(string.Format("{0} is not opened", viewKey)); } ViewItem item = _opened[viewKey]; MediatorItem mediatorItem = _items[viewKey]; if (mediatorItem.closeMethod != null) { mediatorItem.closeMethod.Invoke(item.mediator, null); } _viewFactory.ReleaseView(item.view); _opened.Remove(viewKey); }
public void Open(object viewKey, Argument argument = null) { if (!_items.ContainsKey(viewKey)) { throw new Exception(string.Format("{0} has not been mapped", viewKey)); } if (_opened.ContainsKey(viewKey)) { throw new Exception(string.Format("{0} is already opened", viewKey)); } MediatorItem item = _items[viewKey]; var mediator = Activator.CreateInstance(item.mediatorType); object view = _viewFactory.GetView(item.viewType); _opened.Add(viewKey, new ViewItem { mediator = mediator, view = view }); item.viewField.SetValue(mediator, view); if (_injector != null) { _injector.Inject(mediator, InjectionMode.ResolveOnly); } if (item.argumentField != null) { item.argumentField.SetValue(mediator, argument); } if (item.openMethod != null) { item.openMethod.Invoke(mediator, null); } }