我有一个MenuManager类,每个模块都可以向其中添加要加载到主要内容中的键和元素:
private Dictionary<string,object> _mainContentItems = new Dictionary<string,object>();
public Dictionary<string,object> MainContentItems
{
get { return _mainContentItems; }
set { _mainContentItems = value; }
}
所以客户模块注册它的视图是这样的:
layoutManager.MainContentViews.Add("customer-help", this.container.Resolve<HelpView>());
layoutManager.MainContentViews.Add("customer-main", this.container.Resolve<MainView>());
所以稍后我会说:
layoutManager.ShowMainContentView("customer-help");
为了获得默认视图(注册的第一个视图),我说:
layoutManager.ShowDefaultView("customer");
这很好用。
但是,我想用分隔模块名称和视图名称的连字符消除“代码气味”,所以我想用这个命令注册:
layoutManager.MainContentViews.Add("customer","help", this.container.Resolve<HelpView>());
但是替换我当前的字典的最佳方法是什么,例如,我想到的是这些:
Dictionary<string, string, object> (doesn't exist)
Dictionary<KeyValuePair<string,string>, object>
Dictionary<CUSTOM_STRUCT, object>
新集合需要能够做到这一点:
- 获取带有模块和视图键的视图(例如“客户”、“帮助”返回 1 个视图)
- 通过模块键获取所有视图的集合(例如“客户”返回 5 个视图)