This repository has been archived by the owner on Dec 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFakeDbSerializer.cs
85 lines (79 loc) · 2.55 KB
/
FakeDbSerializer.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
namespace KD.FakeDb.Serialization
{
/// <summary>
/// Serializer used for <see cref="IFakeDatabase"/>.
/// Single file should contains only one <see cref="IFakeDatabase"/>.
/// </summary>
/// <typeparam name="TReader"> Reader type. </typeparam>
/// <typeparam name="TWriter"> Writer type. </typeparam>
public class FakeDbSerializer<TReader, TWriter>
{
private IFakeDatabase _database;
private IFakeDbSerializerConfiguration<TReader, TWriter> _configuration;
/// <summary>
/// Database used for serialization.
/// </summary>
public IFakeDatabase Database
{
get
{
return this._database;
}
set
{
this._database = value;
}
}
/// <summary>
/// Configuration which will be used while serializing and deserializing <see cref="IFakeDatabase"/>.
/// </summary>
public IFakeDbSerializerConfiguration<TReader, TWriter> Configuration
{
get
{
return this._configuration;
}
set
{
this._configuration = value;
}
}
/// <summary>
/// Returns <see cref="Type"/> of a reader.
/// </summary>
public Type ReaderType
{
get
{
return typeof(TReader);
}
}
/// <summary>
/// Returns <see cref="Type"/> of w writer.
/// </summary>
public Type WriterType
{
get
{
return typeof(TWriter);
}
}
/// <summary>
/// Reads <see cref="IFakeDatabase"/> using given reader with specified <see cref="IFakeDbSerializerConfiguration{TReader, TWriter}"/>.
/// </summary>
/// <param name="reader"> Reader which will be used to read <see cref="IFakeDatabase"/>. </param>
public void ReadDatabase(TReader reader)
{
this.Configuration.ReadDatabase(reader, this._database);
}
/// <summary>
/// Writes <see cref="IFakeDatabase"/> using given writer with specified <see cref="IFakeDbSerializerConfiguration{TReader, TWriter}"/>.
/// </summary>
/// <param name="writer"> Writer which will be used to write <see cref="IFakeDatabase"/>. </param>
public void WriteDatabase(TWriter writer)
{
this.Configuration.WriteDatabase(writer, this._database);
}
}
}