-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryFileSerializer.cs
42 lines (29 loc) · 985 Bytes
/
BinaryFileSerializer.cs
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
35
36
37
38
39
40
41
42
using System.IO;
namespace Zenvin.Settings.Framework.Serialization {
/// <summary>
/// Extension of <see cref="BinarySerializer"/>, which automatically writes changes to a file post serialization.
/// </summary>
public sealed class BinaryFileSerializer : BinarySerializer, ISerializerCallbackReceiver {
public FileInfo SaveFile { get; private set; }
public BinaryFileSerializer (string filePath) {
SaveFile = new FileInfo (filePath);
}
public BinaryFileSerializer (FileInfo file) {
SaveFile = file;
}
public bool ReadFromFile () {
return ReadFromFile (SaveFile);
}
public bool WriteToFile () {
return WriteToFile (SaveFile);
}
void ISerializerCallbackReceiver.FinalizeSerialization () {
WriteToFile ();
}
void ISerializerCallbackReceiver.InitializeDeserialization () {
ReadFromFile ();
}
void ISerializerCallbackReceiver.FinalizeDeserialization () { }
void ISerializerCallbackReceiver.InitializeSerialization () { }
}
}