@@ -30,7 +30,6 @@ public abstract class NameValueListBase<[DynamicallyAccessedMembers(DynamicallyA
3030 ICloneable ,
3131 IDataPortalTarget ,
3232 IUseApplicationContext
33- where K : notnull
3433 where V : notnull
3534 {
3635 /// <summary>
@@ -56,14 +55,10 @@ ApplicationContext IUseApplicationContext.ApplicationContext
5655 /// specified key.
5756 /// </summary>
5857 /// <param name="key">Key value for which to retrieve a value.</param>
59- /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
6058 public V ? Value ( K key )
6159 {
62- if ( key is null )
63- throw new ArgumentNullException ( nameof ( key ) ) ;
64-
6560 foreach ( NameValuePair item in this )
66- if ( item . Key . Equals ( key ) )
61+ if ( KeysEqual ( item . Key , key ) )
6762 return item . Value ;
6863 return default ( V ) ;
6964 }
@@ -91,14 +86,10 @@ ApplicationContext IUseApplicationContext.ApplicationContext
9186 /// specified key.
9287 /// </summary>
9388 /// <param name="key">Key value for which to search.</param>
94- /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
9589 public bool ContainsKey ( K key )
9690 {
97- if ( key is null )
98- throw new ArgumentNullException ( nameof ( key ) ) ;
99-
10091 foreach ( NameValuePair item in this )
101- if ( item . Key . Equals ( key ) )
92+ if ( KeysEqual ( item . Key , key ) )
10293 return true ;
10394 return false ;
10495 }
@@ -154,15 +145,11 @@ public bool ContainsValue(V value)
154145 /// Key to search for in the list.
155146 /// </param>
156147 /// <returns>Item from the list.</returns>
157- /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
158148 public NameValuePair ? GetItemByKey ( K key )
159149 {
160- if ( key is null )
161- throw new ArgumentNullException ( nameof ( key ) ) ;
162-
163150 foreach ( NameValuePair item in this )
164151 {
165- if ( item != null && item . Key . Equals ( key ) )
152+ if ( KeysEqual ( item . Key , key ) )
166153 {
167154 return item ;
168155 }
@@ -171,6 +158,11 @@ public bool ContainsValue(V value)
171158
172159 }
173160
161+ private static bool KeysEqual ( K key1 , K key2 )
162+ {
163+ return EqualityComparer < K > . Default . Equals ( key1 , key2 ) ;
164+ }
165+
174166 #endregion
175167
176168 /// <summary>
@@ -227,11 +219,9 @@ public NameValuePair()
227219 /// </summary>
228220 /// <param name="key">The key.</param>
229221 /// <param name="value">The value.</param>
230- /// <exception cref="ArgumentNullException"><paramref name="key "/> is <see langword="null"/>.</exception>
222+ /// <exception cref="ArgumentNullException"><paramref name="value "/> is <see langword="null"/>.</exception>
231223 public NameValuePair ( K key , V value )
232224 {
233- if ( key is null )
234- throw new ArgumentNullException ( nameof ( key ) ) ;
235225 if ( value is null )
236226 throw new ArgumentNullException ( nameof ( value ) ) ;
237227
0 commit comments