我利用Protobuf-net将收集资料编成文件。
我正在设法将另外几个项目合并到现有档案中。
现在我有:
[Test]
public void CanAppend()
{
var list = new List<Person>();
for (int i = 0; i < 1000; i++)
list.Add(new Person {Name = i.ToString(), Age = i});
using (var file = File.Create("person.bin"))
{
Serializer.Serialize<List<Person>>(file, list);
}
list.Clear();
for (int i = 1000; i < 2000; i++)
list.Add(new Person { Name = i.ToString(), Age = i });
using (var file = File.OpenRead("person.bin"))
{
Serializer.Merge<List<Person>>(file, list);
}
using (var file = File.OpenRead("person.bin"))
{
list = Serializer.Deserialize<List<Person>>(file);
}
//Fails here
Assert.That(list.Count, Is.EqualTo(2000));
}
[ProtoContract]
class Person
{
[ProtoMember(1)]
public string Name { get; set; }
[ProtoMember(2)]
public int Age { get; set; }
}
但它没有工作。 任何想法?