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.Excel.Functions.Logical;
|
---|
7 | using OfficeOpenXml.FormulaParsing.Exceptions;
|
---|
8 | using OfficeOpenXml.FormulaParsing.Utilities;
|
---|
9 |
|
---|
10 | namespace 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.