@@ -55,13 +55,12 @@ public IEnumerable<string> Keys
5555 {
5656 get
5757 {
58- if ( this . TryGetValue ( key , out KeyValuePair < string , string > item ) )
58+ if ( ! this . TryGetValue ( key , out string value ) )
5959 {
60- return item . Value ;
60+ ThrowKeyNotFound ( ) ;
6161 }
6262
63- ThrowKeyNotFound ( ) ;
64- return default ;
63+ return value ;
6564 }
6665
6766 set
@@ -72,11 +71,55 @@ public IEnumerable<string> Keys
7271 }
7372 else
7473 {
75- this . Add ( new ( key , value ) ) ;
74+ this . Add ( key , value ) ;
7675 }
7776 }
7877 }
7978
79+ /// <summary>
80+ /// Adds an element with the provided key and value to the <see cref="CommandCollection"/>.
81+ /// </summary>
82+ /// <param name="key">The <see cref="string"/> to use as the key of the element to add.</param>
83+ /// <param name="value">The <see cref="string"/> to use as the value of the element to add.</param>
84+ /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
85+ public void Add ( string key , string value ) => this . Add ( new ( key , value ) ) ;
86+
87+ /// <summary>
88+ /// Inserts an element into the <see cref="CommandCollection"/> at the
89+ /// specified index.
90+ /// </summary>
91+ /// <param name="index">The zero-based index at which item should be inserted.</param>
92+ /// <param name="key">The <see cref="string"/> to use as the key of the element to insert.</param>
93+ /// <param name="value">The <see cref="string"/> to use as the value of the element to insert.</param>
94+ /// <exception cref="ArgumentOutOfRangeException">index is less than zero. -or- index is greater than <see cref="P:CommandCollection.Count"/>.</exception>
95+ public void Insert ( int index , string key , string value ) => this . Insert ( index , new ( key , value ) ) ;
96+
97+ /// <summary>
98+ /// Gets the value associated with the specified key.
99+ /// </summary>
100+ /// <param name="key">The key whose value to get.</param>
101+ /// <param name="value">
102+ /// When this method returns, the value associated with the specified key, if the
103+ /// key is found; otherwise, the default value for the type of the value parameter.
104+ /// This parameter is passed uninitialized.
105+ /// </param>
106+ /// <returns>
107+ /// <see langword="true"/> if the object that implements <see cref="CommandCollection"/> contains
108+ /// an element with the specified key; otherwise, <see langword="false"/>.
109+ /// </returns>
110+ /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
111+ public bool TryGetValue ( string key , out string value )
112+ {
113+ if ( this . TryGetValue ( key , out KeyValuePair < string , string > keyValue ) )
114+ {
115+ value = keyValue . Value ;
116+ return true ;
117+ }
118+
119+ value = default ;
120+ return false ;
121+ }
122+
80123 /// <summary>
81124 /// Searches for an element that matches the conditions defined by the specified
82125 /// predicate, and returns the zero-based index of the first occurrence within the
@@ -109,6 +152,25 @@ public int FindIndex(Predicate<string> match)
109152 return - 1 ;
110153 }
111154
155+ /// <summary>
156+ /// Searches for the specified key and returns the zero-based index of the first
157+ /// occurrence within the entire <see cref="CommandCollection"/>.
158+ /// </summary>
159+ /// <param name="key">The key to locate in the <see cref="CommandCollection"/>.</param>
160+ /// <returns>
161+ /// The zero-based index of the first occurrence of key within the entire <see cref="CommandCollection"/>,
162+ /// if found; otherwise, -1.
163+ /// </returns>
164+ public int IndexOf ( string key )
165+ {
166+ if ( this . TryGetValue ( key , out KeyValuePair < string , string > item ) )
167+ {
168+ return this . IndexOf ( item ) ;
169+ }
170+
171+ return - 1 ;
172+ }
173+
112174 /// <inheritdoc/>
113175 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
114176 protected override string GetKeyForItem ( KeyValuePair < string , string > item ) => item . Key ;
0 commit comments