97 lines
1.6 KiB
C#
97 lines
1.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AspClassic.Scripting.Utils;
|
|
|
|
internal abstract class CheckedDictionaryEnumerator : IDictionaryEnumerator, IEnumerator<KeyValuePair<object, object>>, IDisposable, IEnumerator
|
|
{
|
|
private enum EnumeratorState
|
|
{
|
|
NotStarted,
|
|
Started,
|
|
Ended
|
|
}
|
|
|
|
private EnumeratorState _enumeratorState;
|
|
|
|
public DictionaryEntry Entry
|
|
{
|
|
get
|
|
{
|
|
CheckEnumeratorState();
|
|
return new DictionaryEntry(Key, Value);
|
|
}
|
|
}
|
|
|
|
public object Key
|
|
{
|
|
get
|
|
{
|
|
CheckEnumeratorState();
|
|
return GetKey();
|
|
}
|
|
}
|
|
|
|
public object Value
|
|
{
|
|
get
|
|
{
|
|
CheckEnumeratorState();
|
|
return GetValue();
|
|
}
|
|
}
|
|
|
|
public object Current => Entry;
|
|
|
|
KeyValuePair<object, object> IEnumerator<KeyValuePair<object, object>>.Current => new KeyValuePair<object, object>(Key, Value);
|
|
|
|
private void CheckEnumeratorState()
|
|
{
|
|
if (_enumeratorState == EnumeratorState.NotStarted)
|
|
{
|
|
throw Error.EnumerationNotStarted();
|
|
}
|
|
if (_enumeratorState == EnumeratorState.Ended)
|
|
{
|
|
throw Error.EnumerationFinished();
|
|
}
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
if (_enumeratorState == EnumeratorState.Ended)
|
|
{
|
|
throw Error.EnumerationFinished();
|
|
}
|
|
bool flag = DoMoveNext();
|
|
if (flag)
|
|
{
|
|
_enumeratorState = EnumeratorState.Started;
|
|
}
|
|
else
|
|
{
|
|
_enumeratorState = EnumeratorState.Ended;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
DoReset();
|
|
_enumeratorState = EnumeratorState.NotStarted;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
protected abstract object GetKey();
|
|
|
|
protected abstract object GetValue();
|
|
|
|
protected abstract bool DoMoveNext();
|
|
|
|
protected abstract void DoReset();
|
|
}
|