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