Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using OfficeOpenXml.FormulaParsing.Excel.Functions;
|
---|
6 | using OfficeOpenXml.FormulaParsing.Exceptions;
|
---|
7 |
|
---|
8 | namespace OfficeOpenXml.FormulaParsing.ExpressionGraph.FunctionCompilers
|
---|
9 | {
|
---|
10 | public class IfNaFunctionCompiler : FunctionCompiler
|
---|
11 | {
|
---|
12 | public IfNaFunctionCompiler(ExcelFunction function)
|
---|
13 | :base(function)
|
---|
14 | {
|
---|
15 |
|
---|
16 | }
|
---|
17 |
|
---|
18 | public override CompileResult Compile(IEnumerable<Expression> children, ParsingContext context)
|
---|
19 | {
|
---|
20 | if (children.Count() != 2) throw new ExcelErrorValueException(eErrorType.Value);
|
---|
21 | var args = new List<FunctionArgument>();
|
---|
22 | Function.BeforeInvoke(context);
|
---|
23 | var firstChild = children.First();
|
---|
24 | var lastChild = children.ElementAt(1);
|
---|
25 | try
|
---|
26 | {
|
---|
27 | var result = firstChild.Compile();
|
---|
28 | if (result.DataType == DataType.ExcelError && (Equals(result.Result,
|
---|
29 | ExcelErrorValue.Create(eErrorType.NA))))
|
---|
30 | {
|
---|
31 | args.Add(new FunctionArgument(lastChild.Compile().Result));
|
---|
32 | }
|
---|
33 | else
|
---|
34 | {
|
---|
35 | args.Add(new FunctionArgument(result.Result));
|
---|
36 | }
|
---|
37 |
|
---|
38 | }
|
---|
39 | catch (ExcelErrorValueException ex)
|
---|
40 | {
|
---|
41 | args.Add(new FunctionArgument(lastChild.Compile().Result));
|
---|
42 | }
|
---|
43 | return Function.Execute(args, context);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.