@@ -197,7 +197,7 @@ public KVObject this[string key]
197197 }
198198
199199 /// <summary>
200- /// Gets a child by index (for arrays and collections by insertion order ).
200+ /// Gets a child by index (for arrays and list-backed collections ).
201201 /// </summary>
202202 public KVObject this [ int index ]
203203 {
@@ -208,12 +208,12 @@ public KVObject this[int index]
208208 return GetArrayList ( ) [ index ] ;
209209 }
210210
211- if ( ValueType == KVValueType . Collection )
211+ if ( _ref is List < KeyValuePair < string , KVObject > > list && ValueType == KVValueType . Collection )
212212 {
213- return GetCollectionByIndex ( index ) ;
213+ return list [ index ] . Value ;
214214 }
215215
216- throw new NotSupportedException ( $ "Integer indexer on a { nameof ( KVObject ) } can only be used when the value is an array or collection.") ;
216+ throw new NotSupportedException ( $ "Integer indexer on a { nameof ( KVObject ) } can only be used when the value is an array or list-backed collection.") ;
217217 }
218218 }
219219
@@ -582,13 +582,6 @@ private bool TryInsert(string key, KVObject value, InsertionBehavior behavior)
582582 _ => [ ] ,
583583 } ;
584584
585- private KVObject GetCollectionByIndex ( int index ) => _ref switch
586- {
587- Dictionary < string , KVObject > dict => dict . Values . ElementAt ( index ) ,
588- List < KeyValuePair < string , KVObject > > list => list [ index ] . Value ,
589- _ => throw new InvalidOperationException ( "Not a collection." ) ,
590- } ;
591-
592585 private IEnumerable < KeyValuePair < string , KVObject > > EnumerateArray ( )
593586 {
594587 var list = GetArrayList ( ) ;
0 commit comments