我想声明一个存储IEnumerable特定类型的类型的字典,并将其确切类型作为键,如下所示:(编辑后跟随johny g的评论)
private IDictionary<Type, IEnumerable<T>> _dataOfType where T: BaseClass; //does not compile!
Run Code Online (Sandbox Code Playgroud)
我想要存储的具体类都是从BaseClass派生的,因此想把它当作约束.编译器抱怨它希望在成员名称后面加一个分号.
如果它可以工作,我希望这将使后来从字典中检索简单如下:
IEnumerable<ConcreteData> concreteData;
_sitesOfType.TryGetValue(typeof(ConcreteType), out concreteData);
Run Code Online (Sandbox Code Playgroud)
如何定义这样的字典?