@@ -126,19 +126,19 @@ public interface ISchemaCollection
126
126
127
127
public class ArraySchema < T > : ISchemaCollection
128
128
{
129
- public List < T > Items ;
129
+ public Dictionary < int , T > Items ;
130
130
public event EventHandler < KeyValueEventArgs < T , int > > OnAdd ;
131
131
public event EventHandler < KeyValueEventArgs < T , int > > OnChange ;
132
132
public event EventHandler < KeyValueEventArgs < T , int > > OnRemove ;
133
133
134
134
public ArraySchema ( )
135
135
{
136
- Items = new List < T > ( ) ;
136
+ Items = new Dictionary < int , T > ( ) ;
137
137
}
138
138
139
- public ArraySchema ( List < T > items = null )
139
+ public ArraySchema ( Dictionary < int , T > items = null )
140
140
{
141
- Items = items ?? new List < T > ( ) ;
141
+ Items = items ?? new Dictionary < int , T > ( ) ;
142
142
}
143
143
144
144
public ISchemaCollection Clone ( )
@@ -170,18 +170,21 @@ public int Count
170
170
public T this [ int index ]
171
171
{
172
172
get {
173
- return ( Items . Count > index ) ? ( T ) Items [ index ] : default ( T ) ;
173
+ T value ;
174
+ Items . TryGetValue ( index , out value ) ;
175
+ return value ;
174
176
}
175
- set { Items . Insert ( index , value ) ; }
177
+ set { Items [ index ] = value ; }
176
178
}
177
179
178
180
public object this [ object key ]
179
181
{
180
182
get {
181
- int k = ( int ) key ;
182
- return ( Items . Count > k ) ? ( T ) Items [ k ] : default ( T ) ;
183
+ T value ;
184
+ Items . TryGetValue ( ( int ) key , out value ) ;
185
+ return value ;
183
186
}
184
- set { Items . Insert ( ( int ) key , ( T ) value ) ; }
187
+ set { Items [ ( int ) key ] = ( T ) value ; }
185
188
}
186
189
187
190
public object GetItems ( )
@@ -191,7 +194,15 @@ public object GetItems()
191
194
192
195
public void SetItems ( object items )
193
196
{
194
- Items = ( List < T > ) items ;
197
+ Items = ( Dictionary < int , T > ) items ;
198
+ }
199
+
200
+ public void ForEach ( Action < T > action )
201
+ {
202
+ foreach ( KeyValuePair < int , T > item in Items )
203
+ {
204
+ action ( item . Value ) ;
205
+ }
195
206
}
196
207
197
208
public void TriggerAll ( )
@@ -360,6 +371,14 @@ public void SetItems(object items)
360
371
throw new NotImplementedException ( ) ;
361
372
}
362
373
374
+ public void ForEach ( Action < string , T > action )
375
+ {
376
+ foreach ( KeyValuePair < string , T > item in Items )
377
+ {
378
+ action ( item . Key , item . Value ) ;
379
+ }
380
+ }
381
+
363
382
public void TriggerAll ( )
364
383
{
365
384
if ( OnAdd == null ) { return ; }
0 commit comments