我正在基于ESENT数据库引擎(使用ManagedEsent互操作层)实现通用的持久化.NET集合。到目前为止,我一直专注于完全模仿其System.Collections.Generic对应类的类,不同之处在于它们在构造函数中采用了指示数据库应该到达的位置的路径。像这样的代码正在工作:
using Microsoft.Isam.Esent.Collections.Generic;
static void Main(string[] args)
{
var dictionary = new PersistentDictionary<string, string>("Names");
Console.WriteLine("What is your first name?");
string firstName = Console.ReadLine();
if (dictionary.ContainsKey(firstName))
{
Console.WriteLine("Welcome back {0} {1}", firstName, dictionary[firstName]);
}
else
{
Console.WriteLine("I don't know you, {0}. What is your last name?", firstName);
dictionary[firstName] = Console.ReadLine();
}
}
我的问题是:
下周我将准备好第一个版本,但我想确保自己构建的是正确的东西。
我已经在Codeplex上发布了PersistentDictionary。这仅支持序列化结构,但我将使用支持存储和检索任意对象的不同数据结构。
键上的类型限制可能是可接受的,但是在值上,我希望[Serializable]
起作用。否则,有什么意义呢?像Dictionary<int, string>
这样的简单案例,在教科书中的出现比在现实世界中要多得多。