@@ -35,7 +35,7 @@ public struct ArraySegment<T> : IList<T>, IReadOnlyList<T>
35
35
public ArraySegment ( T [ ] array )
36
36
{
37
37
if ( array == null )
38
- throw new ArgumentNullException ( " array" ) ;
38
+ ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . array ) ;
39
39
Contract . EndContractBlock ( ) ;
40
40
41
41
_array = array ;
@@ -46,13 +46,13 @@ public ArraySegment(T[] array)
46
46
public ArraySegment ( T [ ] array , int offset , int count )
47
47
{
48
48
if ( array == null )
49
- throw new ArgumentNullException ( " array" ) ;
49
+ ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . array ) ;
50
50
if ( offset < 0 )
51
- throw new ArgumentOutOfRangeException ( " offset" , Environment . GetResourceString ( " ArgumentOutOfRange_NeedNonNegNum" ) ) ;
51
+ ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . offset , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
52
52
if ( count < 0 )
53
- throw new ArgumentOutOfRangeException ( " count" , Environment . GetResourceString ( " ArgumentOutOfRange_NeedNonNegNum" ) ) ;
53
+ ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . count , ExceptionResource . ArgumentOutOfRange_NeedNonNegNum ) ;
54
54
if ( array . Length - offset < count )
55
- throw new ArgumentException ( Environment . GetResourceString ( " Argument_InvalidOffLen" ) ) ;
55
+ ThrowHelper . ThrowArgumentException ( ExceptionResource . Argument_InvalidOffLen ) ;
56
56
Contract . EndContractBlock ( ) ;
57
57
58
58
_array = array ;
@@ -146,9 +146,9 @@ T IList<T>.this[int index]
146
146
get
147
147
{
148
148
if ( _array == null )
149
- throw new InvalidOperationException ( Environment . GetResourceString ( " InvalidOperation_NullArray" ) ) ;
149
+ ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_NullArray ) ;
150
150
if ( index < 0 || index >= _count )
151
- throw new ArgumentOutOfRangeException ( " index" ) ;
151
+ ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . index ) ;
152
152
Contract . EndContractBlock ( ) ;
153
153
154
154
return _array [ _offset + index ] ;
@@ -157,9 +157,9 @@ T IList<T>.this[int index]
157
157
set
158
158
{
159
159
if ( _array == null )
160
- throw new InvalidOperationException ( Environment . GetResourceString ( " InvalidOperation_NullArray" ) ) ;
160
+ ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_NullArray ) ;
161
161
if ( index < 0 || index >= _count )
162
- throw new ArgumentOutOfRangeException ( " index" ) ;
162
+ ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . index ) ;
163
163
Contract . EndContractBlock ( ) ;
164
164
165
165
_array [ _offset + index ] = value ;
@@ -169,7 +169,7 @@ T IList<T>.this[int index]
169
169
int IList < T > . IndexOf ( T item )
170
170
{
171
171
if ( _array == null )
172
- throw new InvalidOperationException ( Environment . GetResourceString ( " InvalidOperation_NullArray" ) ) ;
172
+ ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_NullArray ) ;
173
173
Contract . EndContractBlock ( ) ;
174
174
175
175
int index = System . Array . IndexOf < T > ( _array , item , _offset , _count ) ;
@@ -182,12 +182,12 @@ int IList<T>.IndexOf(T item)
182
182
183
183
void IList < T > . Insert ( int index , T item )
184
184
{
185
- throw new NotSupportedException ( ) ;
185
+ ThrowHelper . ThrowNotSupportedException ( ) ;
186
186
}
187
187
188
188
void IList < T > . RemoveAt ( int index )
189
189
{
190
- throw new NotSupportedException ( ) ;
190
+ ThrowHelper . ThrowNotSupportedException ( ) ;
191
191
}
192
192
#endregion
193
193
@@ -197,9 +197,9 @@ T IReadOnlyList<T>.this[int index]
197
197
get
198
198
{
199
199
if ( _array == null )
200
- throw new InvalidOperationException ( Environment . GetResourceString ( " InvalidOperation_NullArray" ) ) ;
200
+ ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_NullArray ) ;
201
201
if ( index < 0 || index >= _count )
202
- throw new ArgumentOutOfRangeException ( " index" ) ;
202
+ ThrowHelper . ThrowArgumentOutOfRangeException ( ExceptionArgument . index ) ;
203
203
Contract . EndContractBlock ( ) ;
204
204
205
205
return _array [ _offset + index ] ;
@@ -220,18 +220,18 @@ bool ICollection<T>.IsReadOnly
220
220
221
221
void ICollection < T > . Add ( T item )
222
222
{
223
- throw new NotSupportedException ( ) ;
223
+ ThrowHelper . ThrowNotSupportedException ( ) ;
224
224
}
225
225
226
226
void ICollection < T > . Clear ( )
227
227
{
228
- throw new NotSupportedException ( ) ;
228
+ ThrowHelper . ThrowNotSupportedException ( ) ;
229
229
}
230
230
231
231
bool ICollection < T > . Contains ( T item )
232
232
{
233
233
if ( _array == null )
234
- throw new InvalidOperationException ( Environment . GetResourceString ( " InvalidOperation_NullArray" ) ) ;
234
+ ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_NullArray ) ;
235
235
Contract . EndContractBlock ( ) ;
236
236
237
237
int index = System . Array . IndexOf < T > ( _array , item , _offset , _count ) ;
@@ -245,23 +245,25 @@ bool ICollection<T>.Contains(T item)
245
245
void ICollection < T > . CopyTo ( T [ ] array , int arrayIndex )
246
246
{
247
247
if ( _array == null )
248
- throw new InvalidOperationException ( Environment . GetResourceString ( " InvalidOperation_NullArray" ) ) ;
248
+ ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_NullArray ) ;
249
249
Contract . EndContractBlock ( ) ;
250
250
251
251
System . Array . Copy ( _array , _offset , array , arrayIndex , _count ) ;
252
252
}
253
253
254
254
bool ICollection < T > . Remove ( T item )
255
255
{
256
- throw new NotSupportedException ( ) ;
256
+ ThrowHelper . ThrowNotSupportedException ( ) ;
257
+ return default ( bool ) ;
258
+
257
259
}
258
260
#endregion
259
261
260
262
#region IEnumerable<T>
261
263
IEnumerator < T > IEnumerable < T > . GetEnumerator ( )
262
264
{
263
265
if ( _array == null )
264
- throw new InvalidOperationException ( Environment . GetResourceString ( " InvalidOperation_NullArray" ) ) ;
266
+ ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_NullArray ) ;
265
267
Contract . EndContractBlock ( ) ;
266
268
267
269
return new ArraySegmentEnumerator ( this ) ;
@@ -272,7 +274,7 @@ IEnumerator<T> IEnumerable<T>.GetEnumerator()
272
274
IEnumerator IEnumerable . GetEnumerator ( )
273
275
{
274
276
if ( _array == null )
275
- throw new InvalidOperationException ( Environment . GetResourceString ( " InvalidOperation_NullArray" ) ) ;
277
+ ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_NullArray ) ;
276
278
Contract . EndContractBlock ( ) ;
277
279
278
280
return new ArraySegmentEnumerator ( this ) ;
@@ -314,8 +316,8 @@ public T Current
314
316
{
315
317
get
316
318
{
317
- if ( _current < _start ) throw new InvalidOperationException ( Environment . GetResourceString ( ResId . InvalidOperation_EnumNotStarted ) ) ;
318
- if ( _current >= _end ) throw new InvalidOperationException ( Environment . GetResourceString ( ResId . InvalidOperation_EnumEnded ) ) ;
319
+ if ( _current < _start ) ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_EnumNotStarted ) ;
320
+ if ( _current >= _end ) ThrowHelper . ThrowInvalidOperationException ( ExceptionResource . InvalidOperation_EnumEnded ) ;
319
321
return _array [ _current ] ;
320
322
}
321
323
}
0 commit comments