Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/FormulaParsing/ExpressionGraph/FunctionCompilers/IfNaFunctionCompiler.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: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using OfficeOpenXml.FormulaParsing.Excel.Functions;
6using OfficeOpenXml.FormulaParsing.Exceptions;
7
8namespace 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.