fbpx

New conditional operator or what?

More
5 months 1 week ago #1 by Karl Faller
New conditional operator or what? was created by Karl Faller
Looking with ILSpy 3 and Fabrice' plugin into some code, i see things like:
self:cRptFile := (self:cRptFile ?? "")
Is this a new short form of default? Or something from the spy-integration?
Or is this old and i did miss it ;-?

Good night!
Karl

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago #2 by Chris Pyrgas
Replied by Chris Pyrgas on topic New conditional operator or what?
Hi Karl,

This is c#'s "Null coalescing" operator according to docs.microsoft.com/en-us/dotnet/csharp/l...reference/operators/

x ?? y – returns x if it is non-null; otherwise, returns y.

(I know, it makes code so easy to read :))

Probably ILSpy processed some code which looked like

IF self:cRptFile == NULL
self:cRptFile := ""
ENDIF

or similar and translated it into the ?? form. But this operator is not supported in X# and the plugin probably did not know how to translate it, so it left it like that.

One solution might be for Fabrice to extend this code to an IF statement, but I don't know if he has such freedom in the plugin. Maybe translate it to an iif() statement instead?

Another solution would be to add support for this operator in the compiler, but personally I'd really prefer not to :)

Chris

XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago #3 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic New conditional operator or what?
Hi Chris,

PMFJI, but was not added a default operator in the last versions of X#?

Wolfgang

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago - 5 months 1 week ago #4 by Robert van der Hulst
Replied by Robert van der Hulst on topic New conditional operator or what?
Wolfgang,

Yes you are right. There is now a DEFAULT expression:
a := b DEFAULT ""
This sets a to b, but if b is NULL then it sets it to ""

Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.
Last edit: 5 months 1 week ago by Robert van der Hulst.

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago #5 by Chris Pyrgas
Replied by Chris Pyrgas on topic New conditional operator or what?
Oops!

XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.