|
8 | 8 | using System.Diagnostics.CodeAnalysis; |
9 | 9 | using System.Globalization; |
10 | 10 | using System.IO; |
11 | | -using System.Linq; |
12 | 11 | using System.Text; |
13 | 12 |
|
14 | 13 | namespace SteamKit2 |
@@ -278,27 +277,28 @@ public KeyValue this[ string key ] |
278 | 277 | { |
279 | 278 | ArgumentNullException.ThrowIfNull( key ); |
280 | 279 |
|
281 | | - var child = this.Children |
282 | | - .FirstOrDefault( c => string.Equals( c.Name, key, StringComparison.OrdinalIgnoreCase ) ); |
283 | | - |
284 | | - if ( child == null ) |
| 280 | + foreach ( var c in this.Children ) |
285 | 281 | { |
286 | | - return Invalid; |
| 282 | + if ( string.Equals( c.Name, key, StringComparison.OrdinalIgnoreCase ) ) |
| 283 | + { |
| 284 | + return c; |
| 285 | + } |
287 | 286 | } |
288 | 287 |
|
289 | | - return child; |
| 288 | + return Invalid; |
290 | 289 | } |
291 | 290 | set |
292 | 291 | { |
293 | 292 | ArgumentNullException.ThrowIfNull( key ); |
294 | 293 |
|
295 | | - var existingChild = this.Children |
296 | | - .FirstOrDefault( c => string.Equals( c.Name, key, StringComparison.OrdinalIgnoreCase ) ); |
297 | | - |
298 | | - if ( existingChild != null ) |
| 294 | + foreach ( var c in this.Children ) |
299 | 295 | { |
300 | | - // if the key already exists, remove the old one |
301 | | - this.Children.Remove( existingChild ); |
| 296 | + if ( string.Equals( c.Name, key, StringComparison.OrdinalIgnoreCase ) ) |
| 297 | + { |
| 298 | + // if the key already exists, remove the old one |
| 299 | + this.Children.Remove( c ); |
| 300 | + break; |
| 301 | + } |
302 | 302 | } |
303 | 303 |
|
304 | 304 | // ensure the given KV actually has the correct key assigned |
@@ -810,7 +810,7 @@ static bool TryReadAsBinaryCore( Stream input, KeyValue current, KeyValue? paren |
810 | 810 | } |
811 | 811 |
|
812 | 812 | current.Name = input.ReadNullTermString( Encoding.UTF8 ); |
813 | | - |
| 813 | + |
814 | 814 | switch ( type ) |
815 | 815 | { |
816 | 816 | case Type.None: |
|
0 commit comments