-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataModel.cs
77 lines (67 loc) · 2.31 KB
/
DataModel.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
using System;
namespace randombg_dotnet{
using DbString = String;
using KeyNotFoundException =
System.Collections.Generic.KeyNotFoundException;
public interface IDbRecord{
string Key{get;}
string ToDbString();
string this[string prop]{get;}
}
public struct ImageRecord: IDbRecord, IEquatable<IDbRecord>{
private const char _DELIM = ';';
public bool HasBeenUsed;
public string Name, Url;
public string Key{get{return Name;}}
public string this[string prop]{
get{
switch(prop){
case "HasBeenUsed":
return HasBeenUsed.ToString();
case "Name":
return Name;
case "Url":
return Url;
default:
throw new KeyNotFoundException(
String.Format(
"{0} does not contain property {1}",
this.GetType().ToString(),
prop));
}
}
}
public ImageRecord(DbString dbstring){
string[] parts = dbstring.Split(_DELIM);
HasBeenUsed = Boolean.Parse(parts[0]);
Name = parts[1];
Url = parts[2];
}
public ImageRecord(bool hasBeenUsed, string name, string url){
HasBeenUsed = hasBeenUsed;
Name = name;
Url = url;
}
public ImageRecord ToggleHasBeenUsed(){
return new ImageRecord(!HasBeenUsed, Name, Url);
}
#region IEquatable<IDbRecord> Implementation
public bool Equals(IDbRecord other){
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return true;
return Key.Equals(other.Key);
}
public override int GetHashCode(){
return Key == null ? 0 : Key.GetHashCode();
}
#endregion
public string ToDbString() {
return string.Join(
_DELIM.ToString(),
HasBeenUsed.ToString(),
Name,
Url);
}
public override string ToString(){ return ToDbString(); }
}
}