Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/FormulaParsing/Excel/Functions/RefAndLookup/ArrayLookupNavigator.cs @ 12074

Last change on this file since 12074 was 12074, checked in by sraggl, 9 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using OfficeOpenXml.FormulaParsing.Exceptions;
6using OfficeOpenXml.FormulaParsing.Utilities;
7
8namespace OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup
9{
10    public class ArrayLookupNavigator : LookupNavigator
11    {
12        private readonly FunctionArgument[] _arrayData;
13        private int _index = 0;
14        private object _currentValue;
15 
16        public ArrayLookupNavigator(LookupDirection direction, LookupArguments arguments, ParsingContext parsingContext)
17            : base(direction, arguments, parsingContext)
18        {
19            Require.That(arguments).Named("arguments").IsNotNull();
20            Require.That(arguments.DataArray).Named("arguments.DataArray").IsNotNull();
21            _arrayData = arguments.DataArray.ToArray();
22            Initialize();
23        }
24
25        private void Initialize()
26        {
27            if (Arguments.LookupIndex >= _arrayData.Length)
28            {
29                throw new ExcelErrorValueException(eErrorType.Ref);
30            }
31            SetCurrentValue();
32
33        }
34
35        public override int Index
36        {
37            get { return _index; }
38        }
39
40        private void SetCurrentValue()
41        {
42            _currentValue = _arrayData[_index];
43        }
44
45        private bool HasNext()
46        {
47            if (Direction == LookupDirection.Vertical)
48            {
49                return _index < (_arrayData.Length - 1);
50            }
51            else
52            {
53                return false;
54            }
55        }
56
57        public override bool MoveNext()
58        {
59            if (!HasNext()) return false;
60            if (Direction == LookupDirection.Vertical)
61            {
62                _index++;
63            }
64            SetCurrentValue();
65            return true;
66        }
67
68        public override object CurrentValue
69        {
70            get { return _arrayData[_index].Value; }
71        }
72
73        public override object GetLookupValue()
74        {
75            return _arrayData[_index].Value;
76        }
77    }
78}
Note: See TracBrowser for help on using the repository browser.