-
Notifications
You must be signed in to change notification settings - Fork 4
/
StringRepository.cs
68 lines (58 loc) · 1.55 KB
/
StringRepository.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
/* Date: 28.8.2014, Time: 0:28 */
using System;
using System.IO;
using AlbLib.Texts;
namespace AlbLib
{
public abstract class StringRepository : Repository<StringRepository.StringResource>
{
protected abstract string OpenImpl(int id);
protected override sealed StringResource GetEntry(int id)
{
return new StringResource(OpenImpl(id));
}
public class StringResource : IGameResource
{
public string Value{get; private set;}
public StringResource(string value)
{
Value = value;
}
public int Save(Stream output)
{
byte[] buffer = TextCore.DefaultEncoding.GetBytes(Value);
output.Write(buffer, 0, buffer.Length);
return buffer.Length;
}
public override string ToString()
{
return Value;
}
#region Equals and GetHashCode implementation
public override bool Equals(object obj)
{
StringRepository.StringResource other = obj as StringRepository.StringResource;
if (other == null)
return false;
return this.Value == other.Value;
}
public override int GetHashCode()
{
return Value.GetHashCode();
}
public static bool operator ==(StringRepository.StringResource lhs, StringRepository.StringResource rhs)
{
if (ReferenceEquals(lhs, rhs))
return true;
if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null))
return false;
return lhs.Equals(rhs);
}
public static bool operator !=(StringRepository.StringResource lhs, StringRepository.StringResource rhs)
{
return !(lhs == rhs);
}
#endregion
}
}
}