MoveNext() public method

public MoveNext ( ) : bool
return bool
Exemplo n.º 1
0
        protected CompileResult Lookup(LookupNavigator navigator, LookupArguments lookupArgs)
        {
            object lastValue       = null;
            object lastLookupValue = null;
            int?   lastMatchResult = null;

            do
            {
                var matchResult = IsMatch(navigator.CurrentValue, lookupArgs.SearchedValue);
                if (matchResult == 0)
                {
                    return(CreateResult(navigator.GetLookupValue(), DataType.String));
                }
                if (lookupArgs.RangeLookup)
                {
                    if (lastValue != null && matchResult > 0 && lastMatchResult < 0)
                    {
                        return(CreateResult(lastLookupValue, DataType.String));
                    }
                    lastMatchResult = matchResult;
                    lastValue       = navigator.CurrentValue;
                    lastLookupValue = navigator.GetLookupValue();
                }
            }while (navigator.MoveNext());

            throw new ExcelFunctionException("Lookupfunction failed to lookup value", ExcelErrorCodes.NoValueAvaliable);
        }
Exemplo n.º 2
0
        protected CompileResult Lookup(LookupNavigator navigator, LookupArguments lookupArgs)
        {
            object lastValue = null;
            object lastLookupValue = null;
            int? lastMatchResult = null;
            do
            {
                var matchResult = IsMatch(navigator.CurrentValue, lookupArgs.SearchedValue);
                if (matchResult == 0)
                {
                    return CreateResult(navigator.GetLookupValue(), DataType.String);
                }
                if (lookupArgs.RangeLookup)
                {
                    if (lastValue != null && matchResult > 0 && lastMatchResult < 0)
                    {
                        return CreateResult(lastLookupValue, DataType.String);
                    }
                    lastMatchResult = matchResult;
                    lastValue = navigator.CurrentValue;
                    lastLookupValue = navigator.GetLookupValue();
                }
            }
            while (navigator.MoveNext());

            throw new ExcelFunctionException("Lookupfunction failed to lookup value", ExcelErrorCodes.NoValueAvaliable);
        }
 public void HasNextShouldBeTrueIfNotLastCell()
 {
     var provider = MockRepository.GenerateStub<ExcelDataProvider>();
     provider.Stub(x => x.GetCellValue(0, 0)).Return(new ExcelCell(3, null, 0, 0));
     provider.Stub(x => x.GetCellValue(1, 0)).Return(new ExcelCell(4, null, 0, 0));
     var args = GetArgs(3, "A1:B2", 1);
     var navigator = new LookupNavigator(LookupDirection.Vertical, args, GetContext(provider));
     Assert.IsTrue(navigator.MoveNext());
 }
 public void MoveNextShouldIncreaseIndex()
 {
     var provider = MockRepository.GenerateStub<ExcelDataProvider>();
     provider.Stub(x => x.GetCellValue(0, 0)).Return(new ExcelCell(3, null, 0, 0));
     provider.Stub(x => x.GetCellValue(1, 0)).Return(new ExcelCell(4, null, 0, 0));
     var args = GetArgs(6, "A1:B2", 1);
     var navigator = new LookupNavigator(LookupDirection.Vertical, args, GetContext(provider));
     Assert.AreEqual(0, navigator.Index);
     navigator.MoveNext();
     Assert.AreEqual(1, navigator.Index);
 }
Exemplo n.º 5
0
        public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context)
        {
            ValidateArguments(arguments, 2);

            var searchedValue       = arguments.ElementAt(0).Value;
            var address             = ArgToString(arguments, 1);
            var rangeAddressFactory = new RangeAddressFactory(context.ExcelDataProvider);
            var rangeAddress        = rangeAddressFactory.Create(address);
            var matchType           = GetMatchType(arguments);
            var args            = new LookupArguments(searchedValue, address, 0, 0, false);
            var lookupDirection = GetLookupDirection(rangeAddress);
            var navigator       = new LookupNavigator(lookupDirection, args, context);
            int?lastMatchResult = default(int?);

            do
            {
                var matchResult = IsMatch(navigator.CurrentValue, searchedValue);
                if (matchType == MatchType.ClosestBelow && matchResult >= 0)
                {
                    if (!lastMatchResult.HasValue && matchResult > 0)
                    {
                        // TODO: error handling. This happens only if the first item is
                        // below the searched value.
                    }
                    var index = matchResult == 0 ? navigator.Index + 1 : navigator.Index;
                    return(CreateResult(index, DataType.Integer));
                }
                if (matchType == MatchType.ClosestAbove && matchResult <= 0)
                {
                    if (!lastMatchResult.HasValue && matchResult < 0)
                    {
                        // TODO: error handling. This happens only if the first item is
                        // above the searched value
                    }
                    var index = matchResult == 0 ? navigator.Index + 1 : navigator.Index;
                    return(CreateResult(index, DataType.Integer));
                }
                if (matchType == MatchType.ExactMatch && matchResult == 0)
                {
                    return(CreateResult(navigator.Index + 1, DataType.Integer));
                }
                lastMatchResult = matchResult;
            }while (navigator.MoveNext());
            return(CreateResult(null, DataType.Integer));
        }
Exemplo n.º 6
0
        public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
        {
            ValidateArguments(arguments, 2);

            var searchedValue = arguments.ElementAt(0).Value;
            var address = ArgToString(arguments, 1);
            var rangeAddressFactory = new RangeAddressFactory(context.ExcelDataProvider);
            var rangeAddress = rangeAddressFactory.Create(address);
            var matchType = GetMatchType(arguments);
            var args = new LookupArguments(searchedValue, address, 0, 0, false);
            var lookupDirection = GetLookupDirection(rangeAddress);
            var navigator = new LookupNavigator(lookupDirection, args, context);
            int? lastMatchResult = default(int?);
            do
            {
                var matchResult = IsMatch(navigator.CurrentValue, searchedValue);
                if (matchType == MatchType.ClosestBelow && matchResult >= 0)
                {
                    if (!lastMatchResult.HasValue && matchResult > 0)
                    {
                        // TODO: error handling. This happens only if the first item is
                        // below the searched value.
                    }
                    var index = matchResult == 0 ? navigator.Index + 1 : navigator.Index;
                    return CreateResult(index, DataType.Integer);
                }
                if (matchType == MatchType.ClosestAbove && matchResult <= 0)
                {
                    if (!lastMatchResult.HasValue && matchResult < 0)
                    {
                        // TODO: error handling. This happens only if the first item is
                        // above the searched value
                    }
                    var index = matchResult == 0 ? navigator.Index + 1 : navigator.Index;
                    return CreateResult(index, DataType.Integer);
                }
                if (matchType == MatchType.ExactMatch && matchResult == 0)
                {
                    return CreateResult(navigator.Index + 1, DataType.Integer);
                }
                lastMatchResult = matchResult;
            }
            while (navigator.MoveNext());
            return CreateResult(null, DataType.Integer);
        }
 public void NavigatorShouldEvaluateFormula()
 {
     var provider = MockRepository.GenerateStub<ExcelDataProvider>();
     provider.Stub(x => x.GetCellValue(0, 0)).Return(new ExcelCell(3, null, 0, 0));
     provider.Stub(x => x.GetCellValue(1, 0)).Return(new ExcelCell(null, "B5", 0, 0));
     var args = GetArgs(4, "A1:B2", 1);
     var context = GetContext(provider);
     var parser = MockRepository.GenerateMock<FormulaParser>(provider);
     context.Parser = parser;
     var navigator = new LookupNavigator(LookupDirection.Vertical, args, context);
     navigator.MoveNext();
     parser.AssertWasCalled(x => x.Parse("B5"));
 }