Reworked script enumerator to not be overriden by generic enumerator

This commit is contained in:
Deukhoofd 2018-12-09 18:23:06 +01:00
parent 50f06f389a
commit ff9eac888f
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
7 changed files with 30 additions and 29 deletions

View File

@ -16,7 +16,7 @@ namespace Upsilon.BaseTypes
public override object ToCSharpObject()
{
return GetEnumerator();
return GetScriptEnumerator();
}
public override System.Type GetCSharpType()
@ -29,7 +29,7 @@ namespace Upsilon.BaseTypes
throw new InvalidOperationException();
}
public abstract IEnumerator<ScriptType> GetEnumerator();
public abstract IEnumerator<ScriptType> GetScriptEnumerator();
}
@ -39,9 +39,9 @@ namespace Upsilon.BaseTypes
{
}
public override IEnumerator<ScriptType> GetEnumerator()
public override IEnumerator<ScriptType> GetScriptEnumerator()
{
using(var baseEnumerator = BaseIterator.GetEnumerator())
using(var baseEnumerator = BaseIterator.GetScriptEnumerator())
{
while (baseEnumerator.MoveNext())
{
@ -63,9 +63,10 @@ namespace Upsilon.BaseTypes
{
}
public override IEnumerator<ScriptType> GetEnumerator()
public override IEnumerator<ScriptType> GetScriptEnumerator()
{
using(var baseEnumerator = BaseIterator.GetEnumerator())
using(var baseEnumerator = BaseIterator.GetScriptEnumerator())
{
while (baseEnumerator.MoveNext())
{

View File

@ -21,5 +21,12 @@ namespace Upsilon.BaseTypes.ScriptTable
return EvaluationScope.Variables.ToDictionary(x => x.Key, x => x.Value.ToCSharpObject());
}
public override IEnumerator<ScriptType> GetScriptEnumerator()
{
foreach (var variable in EvaluationScope.Variables)
{
yield return variable.Key.ToScriptType();
}
}
}
}

View File

@ -11,19 +11,19 @@ namespace Upsilon.BaseTypes.ScriptTable
{
}
public new IEnumerator GetEnumerator()
{
return Enumerator();
}
protected override IEnumerator<ScriptType> Enumerator()
public override IEnumerator<ScriptType> GetScriptEnumerator()
{
foreach (var variable in EvaluationScope.Variables)
{
yield return variable.Value;
yield return variable.Key.ToScriptType();
}
}
IEnumerator<ScriptType> IEnumerable<ScriptType>.GetEnumerator()
{
return GetScriptEnumerator();
}
public override System.Type GetCSharpType()
{
return typeof(IEnumerable<object>);
@ -34,5 +34,9 @@ namespace Upsilon.BaseTypes.ScriptTable
return EvaluationScope.Variables.Select(x => x.Value.ToCSharpObject()).ToArray();
}
public IEnumerator GetEnumerator()
{
return GetScriptEnumerator();
}
}
}

View File

@ -46,18 +46,7 @@ namespace Upsilon.BaseTypes.ScriptTable
throw new Exception($"Can't find key '{index}' in table.");
}
public IEnumerator<ScriptType> GetEnumerator()
{
return Enumerator();
}
protected virtual IEnumerator<ScriptType> Enumerator()
{
foreach (var variable in EvaluationScope.Variables)
{
yield return variable.Key.ToScriptType();
}
}
public abstract IEnumerator<ScriptType> GetScriptEnumerator();
public ScriptNumberLong Length()
{

View File

@ -6,6 +6,6 @@ namespace Upsilon.BaseTypes.ScriptTypeInterfaces
internal interface IIterable
{
ScriptType GetValueFromIndex(ScriptType index);
IEnumerator<ScriptType> GetEnumerator();
IEnumerator<ScriptType> GetScriptEnumerator();
}
}

View File

@ -94,7 +94,7 @@ namespace Upsilon.BaseTypes.UserData
return List[(int) num.Value].ToScriptType();
}
public IEnumerator<ScriptType> GetEnumerator()
public IEnumerator<ScriptType> GetScriptEnumerator()
{
for (int i = 0; i < List.Count; i++)
{

View File

@ -684,7 +684,7 @@ namespace Upsilon.Evaluator
throw new Exception($"Can't iterate over object with type '{enumeratorObject.Type}'");
}
using (var enumerator = iterable.GetEnumerator())
using (var enumerator = iterable.GetScriptEnumerator())
{
while (enumerator.MoveNext())
{