Add in ternary operator support
Opened this issue · 4 comments
Investigate the feasibility of adding in support for ternary operators such as a ? b : c
, etc.
This would be awesome.
I have this kind of expressions:
(variable_1) + [(variable_2 == null) ? 10 : (variable_2)] + [(variable_3 == null) ? 0 : (variable_3)]
I'm aware that this could be rewritten to:
variable_1 + variable_2 ?? 10 + variable_3 ?? 0
but this won't allow me to do this:
(variable_1) + [(variable_2 == variable_3) ? (variable_4) : (variable_5)]
@Misiu yes I really need to find the time to investigate this. In the meantime you could write it as
[variable_1] + If([variable_2] == [variable_3], [variable_4], [variable_5])
It might not be as pretty but it will give the desired result
@bijington thank you for the reply.
Problem is, that I have old system that is using those old-style expressions and I'd like to write a separate API (using. NET 7) and reuse those expressions.
I need to take a look at the source code of your library :)
I noticed that square brackets are used for expressions, do you think they could be used for ternary operator?
@Misiu currently square brackets are reserved to identify a variable name which appears to be different to your example of using standard brackets. I had at one point considered making rules like this configurable but I never had a use case to cover it. That being said even if the brackets could be swapped we would still need the ternary operator added in to support the final part.