4
4
using System ;
5
5
using System . Collections ;
6
6
using System . Collections . Generic ;
7
- using System . IO ;
8
- using System . Linq ;
9
7
10
8
namespace MG . DsReg
11
9
{
12
10
[ Serializable ]
13
- public class WorkAccountCollection : IEnumerable < WorkAccount > , IJsonOutputter
11
+ public class WorkAccountCollection : IReadOnlyList < WorkAccount > , IJsonOutputter
14
12
{
15
- private List < WorkAccount > _list ;
13
+ private SortedList < string , WorkAccount > _list ;
16
14
17
- public WorkAccount this [ int index ] => _list [ index ] ;
15
+ public WorkAccount this [ string tenantName ] => _list [ tenantName ] ;
16
+ public WorkAccount this [ int index ]
17
+ {
18
+ get
19
+ {
20
+ if ( index >= 0 )
21
+ return _list . Values [ index ] ;
22
+
23
+ else
24
+ {
25
+ int goHere = _list . Count + index ;
26
+ return goHere >= 0 ? _list . Values [ goHere ] : null ;
27
+ }
28
+ }
29
+ }
18
30
19
31
public int Count => _list . Count ;
20
32
21
- public WorkAccountCollection ( ) => _list = new List < WorkAccount > ( ) ;
22
- public WorkAccountCollection ( int capacity ) => _list = new List < WorkAccount > ( capacity ) ;
33
+ public WorkAccountCollection ( )
34
+ {
35
+ _list = new SortedList < string , WorkAccount > ( StringComparer . CurrentCultureIgnoreCase ) ;
36
+ }
37
+ public WorkAccountCollection ( int capacity )
38
+ {
39
+ _list = new SortedList < string , WorkAccount > ( capacity , StringComparer . CurrentCultureIgnoreCase ) ;
40
+ }
41
+
42
+ internal void Add ( WorkAccount wa )
43
+ {
44
+ if ( _list . ContainsKey ( wa . WorkplaceTenantName ) )
45
+ return ;
23
46
24
- internal void Add ( WorkAccount wa ) => _list . Add ( wa ) ;
47
+ _list . Add ( wa . WorkplaceTenantName , wa ) ;
48
+ }
25
49
26
- public IEnumerator < WorkAccount > GetEnumerator ( ) => ( ( IEnumerable < WorkAccount > ) _list ) . GetEnumerator ( ) ;
27
- IEnumerator IEnumerable . GetEnumerator ( ) => ( ( IEnumerable < WorkAccount > ) _list ) . GetEnumerator ( ) ;
50
+ public IEnumerator < WorkAccount > GetEnumerator ( )
51
+ {
52
+ return _list . Values . GetEnumerator ( ) ;
53
+ }
54
+ IEnumerator IEnumerable . GetEnumerator ( )
55
+ {
56
+ return this . GetEnumerator ( ) ;
57
+ }
28
58
29
59
public string ToJson ( )
30
60
{
@@ -40,10 +70,9 @@ public string ToJson()
40
70
serializer . Converters . Add ( new StringEnumConverter ( new CamelCaseNamingStrategy ( ) ) ) ;
41
71
return this . ToJson ( serializer ) ;
42
72
}
43
-
44
73
public string ToJson ( JsonSerializerSettings serializerSettings )
45
74
{
46
- return JsonConvert . SerializeObject ( this , serializerSettings ) ;
75
+ return JsonConvert . SerializeObject ( _list . Values , serializerSettings ) ;
47
76
}
48
77
}
49
78
}
0 commit comments