@@ -120,16 +120,10 @@ void ICollection.CopyTo(Array array, int index)
120
120
return ;
121
121
}
122
122
123
- if ( array . GetType ( ) . GetElementType ( ) . IsAssignableFrom ( typeof ( T ) ) )
124
- {
125
- if ( _hasNull )
126
- array . SetValue ( default ( T ) , index ) ;
127
- ICollection keysCollection = _values . Keys ;
128
- keysCollection . CopyTo ( array , index + ( _hasNull ? 1 : 0 ) ) ;
129
- return ;
130
- }
131
-
132
- throw new ArgumentException ( $ "Array must be of type { typeof ( T [ ] ) } .", nameof ( array ) ) ;
123
+ if ( _hasNull )
124
+ array . SetValue ( default ( T ) , index ) ;
125
+ ICollection keysCollection = _values . Keys ;
126
+ keysCollection . CopyTo ( array , index + ( _hasNull ? 1 : 0 ) ) ;
133
127
}
134
128
135
129
public int Count => _values . Count + ( _hasNull ? 1 : 0 ) ;
@@ -163,12 +157,14 @@ protected SetSnapShot(SerializationInfo info, StreamingContext context) : base(i
163
157
164
158
void ICollection . CopyTo ( Array array , int index )
165
159
{
166
- if ( ! ( array is T [ ] typedArray ) )
160
+ if ( array is T [ ] typedArray )
167
161
{
168
- throw new ArgumentException ( $ "Array must be of type { typeof ( T [ ] ) } .", nameof ( array ) ) ;
162
+ CopyTo ( typedArray , index ) ;
163
+ return ;
169
164
}
170
165
171
- CopyTo ( typedArray , index ) ;
166
+ ICollection collection = this ;
167
+ collection . CopyTo ( array , index ) ;
172
168
}
173
169
174
170
bool ICollection . IsSynchronized => false ;
0 commit comments