【发布时间】:2011-10-08 00:18:34
【问题描述】:
我不知道该怎么做...
我有一个执行各种功能的类:
public abstract class EntityBase { ... }
public interface ISomeInterface<T> where T : EntityBase, new() { ... }
public class SomeClass<T> : ISomeInterface<T> { ... }
我正在尝试在非泛型类中缓存这些:
public class MyClass
{
//Not sure how to do this
private ConcurrentDictionary<?, ISomeInterface<?>> Cache { get; set; }
}
问题是 EntityBase 是抽象的,不能做 new(),ISomeInterface 需要一个基于 EntityBase 的类并做 new()。有什么办法可以做我想做的事吗?
更新:我意识到我可以为 TKey 使用 Type,但我仍然不确定 ISomeInterface 应该放什么。
【问题讨论】:
标签: c# generics collections dictionary constraints