44
55namespace ValveKeyValue
66{
7- class KVArrayValue : KVValue , IEnumerable < KVValue >
7+ public class KVArrayValue : KVValue , IEnumerable < KVValue > , ICollection < KVValue > , IList < KVValue >
88 {
99 public KVArrayValue ( )
1010 {
@@ -15,16 +15,26 @@ public KVArrayValue()
1515
1616 public override KVValueType ValueType => KVValueType . Array ;
1717
18- /*
18+ public int Count => children . Count ;
19+
20+ public bool IsReadOnly => false ;
21+
1922 public override KVValue this [ string key ]
23+ {
24+ get { throw new NotSupportedException ( $ "The indexer on a { nameof ( KVArrayValue ) } can only be used on integer keys, not strings.") ; }
25+ }
26+
27+ public KVValue this [ int key ]
2028 {
2129 get
2230 {
23- Require.NotNull(key, nameof(key));
24- return Get(key)?.Value;
31+ return children [ key ] ;
32+ }
33+ set
34+ {
35+ children [ key ] = value ;
2536 }
2637 }
27- */
2838
2939 public void Add ( KVValue value )
3040 {
@@ -38,23 +48,6 @@ public void AddRange(IEnumerable<KVValue> values)
3848 children . AddRange ( values ) ;
3949 }
4050
41- /*
42- public KVObject Get(string name)
43- {
44- Require.NotNull(name, nameof(name));
45- return children.FirstOrDefault(c => c.Name == name);
46- }
47-
48- public void Set(string name, KVValue value)
49- {
50- Require.NotNull(name, nameof(name));
51- Require.NotNull(value, nameof(value));
52-
53- children.RemoveAll(kv => kv.Name == name);
54- children.Add(new KVObject(name, value));
55- }
56- */
57-
5851 #region IEnumerable<KVValue>
5952
6053 public IEnumerator < KVValue > GetEnumerator ( ) => children . GetEnumerator ( ) ;
@@ -155,5 +148,39 @@ public override ulong ToUInt64(IFormatProvider provider)
155148 #endregion
156149
157150 public override string ToString ( ) => "[Array]" ;
151+
152+ public void Clear ( ) => children . Clear ( ) ;
153+
154+ public bool Contains ( KVValue item )
155+ {
156+ Require . NotNull ( item , nameof ( item ) ) ;
157+ return children . Contains ( item ) ;
158+ }
159+
160+ public void CopyTo ( KVValue [ ] array , int arrayIndex )
161+ {
162+ Require . NotNull ( array , nameof ( array ) ) ;
163+ children . CopyTo ( array , arrayIndex ) ;
164+ }
165+
166+ public bool Remove ( KVValue item )
167+ {
168+ Require . NotNull ( item , nameof ( item ) ) ;
169+ return children . Remove ( item ) ;
170+ }
171+
172+ public int IndexOf ( KVValue item )
173+ {
174+ Require . NotNull ( item , nameof ( item ) ) ;
175+ return children . IndexOf ( item ) ;
176+ }
177+
178+ public void Insert ( int index , KVValue item )
179+ {
180+ Require . NotNull ( item , nameof ( item ) ) ;
181+ children . Insert ( index , item ) ;
182+ }
183+
184+ public void RemoveAt ( int index ) => children . RemoveAt ( index ) ;
158185 }
159186}
0 commit comments