Hi!
Currently ClosedXML is only able to handle the "IF"-function if supplied with 3 arguments, but this function can also be called with only 2 arguments. ie. something like "IF(M49="111";94)" will return 0 if the predicate is false.
Modifications are necessary in the file "Logical.cs", two methods need to be updated:
```
public static void Register(CalcEngine ce)
{
ce.RegisterFunction("AND", 1, int.MaxValue, And);
ce.RegisterFunction("OR", 1, int.MaxValue, Or);
ce.RegisterFunction("NOT", 1, Not);
ce.RegisterFunction("IF", 2, 3, If);
ce.RegisterFunction("TRUE", 0, True);
ce.RegisterFunction("FALSE", 0, False);
}
```
and
```
static object If(List<Expression> p)
{
if (p.Count == 2) {
var val = p[1].Evaluate();
return (bool) p[0]
? val
: val.GetType().IsValueType
? Activator.CreateInstance(val.GetType())
: null;
} else {
return (bool)p[0]
? p[1].Evaluate()
: p[2].Evaluate();
}
}
```
Cheers,
Ted
Currently ClosedXML is only able to handle the "IF"-function if supplied with 3 arguments, but this function can also be called with only 2 arguments. ie. something like "IF(M49="111";94)" will return 0 if the predicate is false.
Modifications are necessary in the file "Logical.cs", two methods need to be updated:
```
public static void Register(CalcEngine ce)
{
ce.RegisterFunction("AND", 1, int.MaxValue, And);
ce.RegisterFunction("OR", 1, int.MaxValue, Or);
ce.RegisterFunction("NOT", 1, Not);
ce.RegisterFunction("IF", 2, 3, If);
ce.RegisterFunction("TRUE", 0, True);
ce.RegisterFunction("FALSE", 0, False);
}
```
and
```
static object If(List<Expression> p)
{
if (p.Count == 2) {
var val = p[1].Evaluate();
return (bool) p[0]
? val
: val.GetType().IsValueType
? Activator.CreateInstance(val.GetType())
: null;
} else {
return (bool)p[0]
? p[1].Evaluate()
: p[2].Evaluate();
}
}
```
Cheers,
Ted