Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in ternary operator support #51

Open
bijington opened this issue Jul 14, 2019 · 4 comments
Open

Add in ternary operator support #51

bijington opened this issue Jul 14, 2019 · 4 comments

Comments

@bijington
Copy link
Owner

Investigate the feasibility of adding in support for ternary operators such as a ? b : c, etc.

@Misiu
Copy link

Misiu commented Jan 12, 2023

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)]

@bijington
Copy link
Owner Author

@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

@Misiu
Copy link

Misiu commented Jan 12, 2023

@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?

@bijington
Copy link
Owner Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants