blob: 1e5075ab35f573363f3a0a29aee0b4d747f44130 [file] [log] [blame]
using System.Collections.Generic;
using System.Linq;
namespace AppsheetEpplus;
public class IfNaFunctionCompiler : FunctionCompiler {
public IfNaFunctionCompiler(ExcelFunction function)
: base(function) {}
public override CompileResult Compile(IEnumerable<Expression> children, ParsingContext context) {
if (children.Count() != 2) {
throw new ExcelErrorValueException(eErrorType.Value);
}
var args = new List<FunctionArgument>();
Function.BeforeInvoke(context);
var firstChild = children.First();
var lastChild = children.ElementAt(1);
try {
var result = firstChild.Compile();
if (result.DataType == DataType.ExcelError
&& (Equals(result.Result, ExcelErrorValue.Create(eErrorType.Na)))) {
args.Add(new(lastChild.Compile().Result));
} else {
args.Add(new(result.Result));
}
} catch (ExcelErrorValueException) {
args.Add(new(lastChild.Compile().Result));
}
return Function.Execute(args, context);
}
}