Open cdarrigo opened 1 year ago
Have you actually tried such an operation and see what you get?
Seems it's not supported:
[Fact]
public void Expression_Ternary_Operator()
{
ExpressionContext expressionContext = new();
expressionContext.Imports.AddType(typeof(Math));
expressionContext.Variables["operation"] = true; //or subtract
IGenericExpression<int> eGeneric = expressionContext.CompileGeneric<int>("operation ? 1+3 : 1-3");
var actual = eGeneric.Evaluate();
actual.ShouldBe(4);
}
The above fails with the following error: Flee.Parsing.ParserLogException : unexpected character '?', on line: 1 column: 11
When I needed a ternary function, I wrote a simple custom method named IIf (boolExpression, trueValue, falseValue) that returned trueValue when boolExpression evaluated to true, and falseValue when it evaluated to false.
The conditional operator ?:, also known as the ternary conditional operator, evaluates a Boolean expression and returns the result of one of the two expressions, depending on whether the Boolean expression evaluates to true or false.
Is this type of operation supported in Flee?