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