@@ -12,8 +12,6 @@ namespace SixLabors.ImageSharp.Web.Commands
1212 /// </summary>
1313 public sealed class CommandCollection : KeyedCollection < string , KeyValuePair < string , string > >
1414 {
15- private readonly List < string > keys = new ( ) ;
16-
1715 /// <summary>
1816 /// Initializes a new instance of the <see cref="CommandCollection"/> class.
1917 /// </summary>
@@ -28,9 +26,18 @@ private CommandCollection(IEqualityComparer<string> comparer)
2826 }
2927
3028 /// <summary>
31- /// Gets an <see cref="ICollection{T }"/> representing the keys of the collection.
29+ /// Gets an <see cref="IEnumerable{String }"/> representing the keys of the collection.
3230 /// </summary>
33- public ICollection < string > Keys => this . keys ;
31+ public IEnumerable < string > Keys
32+ {
33+ get
34+ {
35+ foreach ( KeyValuePair < string , string > item in this )
36+ {
37+ yield return this . GetKeyForItem ( item ) ;
38+ }
39+ }
40+ }
3441
3542 /// <summary>
3643 /// Gets or sets the value associated with the specified key.
@@ -60,41 +67,14 @@ private CommandCollection(IEqualityComparer<string> comparer)
6067 if ( this . TryGetValue ( key , out KeyValuePair < string , string > item ) )
6168 {
6269 this . SetItem ( this . IndexOf ( item ) , new ( key , value ) ) ;
63- return ;
6470 }
65-
66- throw new KeyNotFoundException ( ) ;
71+ else
72+ {
73+ this . Add ( new ( key , value ) ) ;
74+ }
6775 }
6876 }
6977
70- /// <inheritdoc/>
71- protected override void InsertItem ( int index , KeyValuePair < string , string > item )
72- {
73- base . InsertItem ( index , item ) ;
74- this . keys . Insert ( index , item . Key ) ;
75- }
76-
77- /// <inheritdoc/>
78- protected override void RemoveItem ( int index )
79- {
80- base . RemoveItem ( index ) ;
81- this . keys . RemoveAt ( index ) ;
82- }
83-
84- /// <inheritdoc/>
85- protected override void SetItem ( int index , KeyValuePair < string , string > item )
86- {
87- base . SetItem ( index , item ) ;
88- this . keys [ index ] = item . Key ;
89- }
90-
91- /// <inheritdoc/>
92- protected override void ClearItems ( )
93- {
94- base . ClearItems ( ) ;
95- this . keys . Clear ( ) ;
96- }
97-
9878 /// <inheritdoc/>
9979 protected override string GetKeyForItem ( KeyValuePair < string , string > item ) => item . Key ;
10080 }
0 commit comments