@@ -31,11 +31,13 @@ public class UserScore {
31
31
public static string UsernamePath = "username" ;
32
32
public static string ScorePath = "score" ;
33
33
public static string TimestampPath = "timestamp" ;
34
+ public static string OtherDataPath = "data" ;
34
35
35
36
public string UserID ;
36
37
public string Username ;
37
38
public long Score ;
38
39
public long Timestamp ;
40
+ public Dictionary < string , object > OtherData ;
39
41
40
42
/// <summary>
41
43
/// Timestamp is stored as a long value, seconds since Epoch time. This property
@@ -71,11 +73,18 @@ public UserScore(string userId, long score, long timestamp) {
71
73
/// <param name="username">The user's display name.</param>
72
74
/// <param name="score">The score value.</param>
73
75
/// <param name="timestamp">The timestamp the score was achieved.</param>
74
- public UserScore ( string userId , string username , long score , long timestamp ) {
76
+ /// <param name="otherData">Miscellaneous data to store with the score object.</param>
77
+ public UserScore (
78
+ string userId ,
79
+ string username ,
80
+ long score ,
81
+ long timestamp ,
82
+ Dictionary < string , object > otherData = null ) {
75
83
UserID = userId ;
76
84
Username = username ;
77
85
Score = score ;
78
86
Timestamp = timestamp ;
87
+ OtherData = otherData ;
79
88
}
80
89
81
90
/// <summary>
@@ -97,6 +106,12 @@ public UserScore(DataSnapshot record) {
97
106
if ( Int64 . TryParse ( record . Child ( TimestampPath ) . Value . ToString ( ) , out timestamp ) ) {
98
107
Timestamp = timestamp ;
99
108
}
109
+ if ( record . Child ( OtherDataPath ) . Exists && record . Child ( OtherDataPath ) . HasChildren ) {
110
+ OtherData = new Dictionary < string , object > ( ) ;
111
+ foreach ( var datum in record . Child ( OtherDataPath ) . Children ) {
112
+ OtherData [ datum . Key ] = datum . Value ;
113
+ }
114
+ }
100
115
}
101
116
102
117
/// <summary>
@@ -109,7 +124,8 @@ public Dictionary<string, object> ToDictionary() {
109
124
{ UserIDPath , UserID } ,
110
125
{ UsernamePath , Username } ,
111
126
{ ScorePath , Score } ,
112
- { TimestampPath , Timestamp }
127
+ { TimestampPath , Timestamp } ,
128
+ { OtherDataPath , OtherData }
113
129
} ;
114
130
}
115
131
0 commit comments