我无法弄清楚这里发生了什么。我正在构建Dictionary集合的包装器。这个想法是,当集合的大小很小时,它将使用正常的内存中字典;但是,当达到阈值数量的项目时,它将在内部切换到磁盘上的字典(我正在使用ManagedEsent PersistentDictionary类)。无法限制泛型类型
以下是磁盘版本的一个片段。编译时,它失败,出现以下错误:
"The type 'T_KEY' cannot be used as type parameter 'TKey' in the generic type or method 'Microsoft.Isam.Esent.Collections.Generic.PersistentDictionary<TKey,TValue>'. There is no boxing conversion or type parameter conversion from 'T_KEY' to 'System.IComparable<T_KEY>'."
所以我修改类的定义是:
class DiskDictionary<T_KEY, T_VALUE> : IHybridDictionary<T_KEY, T_VALUE>
where T_KEY : System.IComparable
思想,会做的伎俩,但事实并非如此。我试图限制IHybridDictionary的定义,但没有任何效果。对发生什么事情有任何想法?
DiskDictionary的最初的定义:
class DiskDictionary<T_KEY, T_VALUE> : IHybridDictionary<T_KEY, T_VALUE>
{
string dir;
PersistentDictionary<T_KEY, T_VALUE> d;
public DiskDictionary(string dir)
{
this.dir = dir;
//d = new PersistentDictionary<T_KEY, T_VALUE>(dir);
}
... some other methods...
}
啊,非常感谢。我最初尝试过,并没有奏效,但我没有通过其他类定义来传播它。 – Gadzooks34