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>
2020 protected T DefaultValue => default ( T ) ;
2121
2222 protected bool MoveNextAtEndThrowsOnModifiedCollection => true ;
23+ protected virtual bool CurrentAfterFullEnumerationThrows => true ;
2324
2425 protected virtual CollectionOrder CollectionOrder => CollectionOrder . Sequential ;
2526
@@ -352,7 +353,7 @@ public void EnumeratePastEndThenModify()
352353 VerifyModifiedEnumerator (
353354 enumerator ,
354355 DefaultValue ,
355- false ,
356+ CurrentAfterFullEnumerationThrows ,
356357 true ) ;
357358 }
358359
Original file line number Diff line number Diff line change @@ -391,6 +391,7 @@ public ReadOnlyDictionaryOverNonGenericTests()
391391 protected override bool IsGenericCompatibility { get { return false ; } }
392392 protected override bool ItemsMustBeUnique { get { return true ; } }
393393 protected override bool ItemsMustBeNonNull { get { return true ; } }
394+ protected override bool CurrentAfterFullEnumerationThrows { get { return false ; } }
394395 protected override object GenerateItem ( )
395396 {
396397 return new KeyValuePair < string , int > ( m_next_item . ToString ( ) , m_next_item ++ ) ;
@@ -429,6 +430,7 @@ public ReadOnlyDictionaryTestsStringInt()
429430 protected override bool IsGenericCompatibility { get { return false ; } }
430431 protected override bool ItemsMustBeUnique { get { return true ; } }
431432 protected override bool ItemsMustBeNonNull { get { return true ; } }
433+ protected override bool CurrentAfterFullEnumerationThrows { get { return false ; } }
432434 protected override object GenerateItem ( )
433435 {
434436 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)
11851185 public struct Enumerator : IEnumerator < T > , IEnumerator
11861186 {
11871187 private readonly List < T > _list ;
1188- private int _index ;
11891188 private readonly int _version ;
1189+
1190+ private int _index ;
11901191 private T ? _current ;
11911192
11921193 internal Enumerator ( List < T > list )
11931194 {
11941195 _list = list ;
1195- _index = 0 ;
11961196 _version = list . _version ;
1197- _current = default ;
11981197 }
11991198
12001199 public void Dispose ( )
@@ -1205,24 +1204,20 @@ public bool MoveNext()
12051204 {
12061205 List < T > localList = _list ;
12071206
1208- if ( _version == localList . _version && ( ( uint ) _index < ( uint ) localList . _size ) )
1207+ if ( _version != _list . _version )
12091208 {
1210- _current = localList . _items [ _index ] ;
1211- _index ++ ;
1212- return true ;
1209+ ThrowHelper . ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion ( ) ;
12131210 }
1214- return MoveNextRare ( ) ;
1215- }
12161211
1217- private bool MoveNextRare ( )
1218- {
1219- if ( _version != _list . _version )
1212+ if ( ( uint ) _index < ( uint ) localList . _size )
12201213 {
1221- ThrowHelper . ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion ( ) ;
1214+ _current = localList . _items [ _index ] ;
1215+ _index ++ ;
1216+ return true ;
12221217 }
12231218
1224- _index = _list . _size + 1 ;
12251219 _current = default ;
1220+ _index = - 1 ;
12261221 return false ;
12271222 }
12281223
@@ -1232,11 +1227,12 @@ private bool MoveNextRare()
12321227 {
12331228 get
12341229 {
1235- if ( _index == 0 || _index == _list . _size + 1 )
1230+ if ( _index <= 0 )
12361231 {
12371232 ThrowHelper . ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen ( ) ;
12381233 }
1239- return Current ;
1234+
1235+ return _current ;
12401236 }
12411237 }
12421238
You can’t perform that action at this time.
0 commit comments