progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
97
AspClassic.Scripting/Utils/CheckedDictionaryEnumerator.cs
Normal file
97
AspClassic.Scripting/Utils/CheckedDictionaryEnumerator.cs
Normal file
|
@ -0,0 +1,97 @@
|
|||
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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue