File tree Expand file tree Collapse file tree 3 files changed +16
-17
lines changed
Common/tests/System/Collections
System.ObjectModel/tests/ReadOnlyDictionary
System.Private.CoreLib/src/System/Collections/Generic Expand file tree Collapse file tree 3 files changed +16
-17
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ public abstract class IEnumerableTest<T>
20
20
protected T DefaultValue => default ( T ) ;
21
21
22
22
protected bool MoveNextAtEndThrowsOnModifiedCollection => true ;
23
+ protected virtual bool CurrentAfterFullEnumerationThrows => true ;
23
24
24
25
protected virtual CollectionOrder CollectionOrder => CollectionOrder . Sequential ;
25
26
@@ -352,7 +353,7 @@ public void EnumeratePastEndThenModify()
352
353
VerifyModifiedEnumerator (
353
354
enumerator ,
354
355
DefaultValue ,
355
- false ,
356
+ CurrentAfterFullEnumerationThrows ,
356
357
true ) ;
357
358
}
358
359
Original file line number Diff line number Diff line change @@ -391,6 +391,7 @@ public ReadOnlyDictionaryOverNonGenericTests()
391
391
protected override bool IsGenericCompatibility { get { return false ; } }
392
392
protected override bool ItemsMustBeUnique { get { return true ; } }
393
393
protected override bool ItemsMustBeNonNull { get { return true ; } }
394
+ protected override bool CurrentAfterFullEnumerationThrows { get { return false ; } }
394
395
protected override object GenerateItem ( )
395
396
{
396
397
return new KeyValuePair < string , int > ( m_next_item . ToString ( ) , m_next_item ++ ) ;
@@ -429,6 +430,7 @@ public ReadOnlyDictionaryTestsStringInt()
429
430
protected override bool IsGenericCompatibility { get { return false ; } }
430
431
protected override bool ItemsMustBeUnique { get { return true ; } }
431
432
protected override bool ItemsMustBeNonNull { get { return true ; } }
433
+ protected override bool CurrentAfterFullEnumerationThrows { get { return false ; } }
432
434
protected override object GenerateItem ( )
433
435
{
434
436
return new KeyValuePair < string , int > ( m_next_item . ToString ( ) , m_next_item ++ ) ;
Original file line number Diff line number Diff line change @@ -1185,16 +1185,15 @@ public bool TrueForAll(Predicate<T> match)
1185
1185
public struct Enumerator : IEnumerator < T > , IEnumerator
1186
1186
{
1187
1187
private readonly List < T > _list ;
1188
- private int _index ;
1189
1188
private readonly int _version ;
1189
+
1190
+ private int _index ;
1190
1191
private T ? _current ;
1191
1192
1192
1193
internal Enumerator ( List < T > list )
1193
1194
{
1194
1195
_list = list ;
1195
- _index = 0 ;
1196
1196
_version = list . _version ;
1197
- _current = default ;
1198
1197
}
1199
1198
1200
1199
public void Dispose ( )
@@ -1205,24 +1204,20 @@ public bool MoveNext()
1205
1204
{
1206
1205
List < T > localList = _list ;
1207
1206
1208
- if ( _version == localList . _version && ( ( uint ) _index < ( uint ) localList . _size ) )
1207
+ if ( _version != _list . _version )
1209
1208
{
1210
- _current = localList . _items [ _index ] ;
1211
- _index ++ ;
1212
- return true ;
1209
+ ThrowHelper . ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion ( ) ;
1213
1210
}
1214
- return MoveNextRare ( ) ;
1215
- }
1216
1211
1217
- private bool MoveNextRare ( )
1218
- {
1219
- if ( _version != _list . _version )
1212
+ if ( ( uint ) _index < ( uint ) localList . _size )
1220
1213
{
1221
- ThrowHelper . ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion ( ) ;
1214
+ _current = localList . _items [ _index ] ;
1215
+ _index ++ ;
1216
+ return true ;
1222
1217
}
1223
1218
1224
- _index = _list . _size + 1 ;
1225
1219
_current = default ;
1220
+ _index = - 1 ;
1226
1221
return false ;
1227
1222
}
1228
1223
@@ -1232,11 +1227,12 @@ private bool MoveNextRare()
1232
1227
{
1233
1228
get
1234
1229
{
1235
- if ( _index == 0 || _index == _list . _size + 1 )
1230
+ if ( _index <= 0 )
1236
1231
{
1237
1232
ThrowHelper . ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen ( ) ;
1238
1233
}
1239
- return Current ;
1234
+
1235
+ return _current ;
1240
1236
}
1241
1237
}
1242
1238
You can’t perform that action at this time.
0 commit comments