main
 1using System.IO;
 2using System.Runtime.Serialization;
 3
 4namespace jive
 5{
 6  public class FileStreamSerializer<T> : Serializer<T>
 7  {
 8    public FileStreamSerializer(string file_path, IFormatter formatter)
 9    {
10      this.file_path = file_path;
11      this.formatter = formatter;
12    }
13
14    public void serialize(T to_serialize)
15    {
16      using (var stream = new FileStream(file_path, FileMode.Create, FileAccess.Write))
17        formatter.Serialize(stream, to_serialize);
18    }
19
20    public T deserialize()
21    {
22      using (var stream = new FileStream(file_path, FileMode.Open, FileAccess.Read))
23        return (T) formatter.Deserialize(stream);
24    }
25
26    public void Dispose()
27    {
28      File.Delete(file_path);
29    }
30
31    readonly string file_path;
32    readonly IFormatter formatter;
33  }
34}