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);
}