blob: 59cc919b51fc1bb8db436bab1b40aee67b5196d4 [file] [log] [blame] [edit]
using System.Linq;
namespace AppsheetEpplus;
public class ArrayLookupNavigator : LookupNavigator {
private readonly FunctionArgument[] _arrayData;
private int _index;
private object _currentValue;
public ArrayLookupNavigator(
LookupDirection direction,
LookupArguments arguments,
ParsingContext parsingContext)
: base(direction, arguments, parsingContext) {
Require.That(arguments).Named("arguments").IsNotNull();
Require.That(arguments.DataArray).Named("arguments.DataArray").IsNotNull();
_arrayData = arguments.DataArray.ToArray();
Initialize();
}
private void Initialize() {
if (Arguments.LookupIndex >= _arrayData.Length) {
throw new ExcelErrorValueException(eErrorType.Ref);
}
SetCurrentValue();
}
public override int Index => _index;
private void SetCurrentValue() {
_currentValue = _arrayData[_index];
}
private bool HasNext() {
if (Direction == LookupDirection.Vertical) {
return _index < (_arrayData.Length - 1);
}
return false;
}
public override bool MoveNext() {
if (!HasNext()) {
return false;
}
if (Direction == LookupDirection.Vertical) {
_index++;
}
SetCurrentValue();
return true;
}
public override object CurrentValue => _arrayData[_index].Value;
public override object GetLookupValue() {
return _arrayData[_index].Value;
}
}