xsharp.eu • New conditional operator or what?
Page 1 of 1

New conditional operator or what?

Posted: Sat Aug 04, 2018 8:22 pm
by FFF
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

New conditional operator or what?

Posted: Sat Aug 04, 2018 11:04 pm
by Chris
Hi Karl,

This is c#'s "Null coalescing" operator according to https://docs.microsoft.com/en-us/dotnet ... 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

New conditional operator or what?

Posted: Sun Aug 05, 2018 7:09 am
by wriedmann
Hi Chris,

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

Wolfgang

New conditional operator or what?

Posted: Sun Aug 05, 2018 9:44 am
by robert
Wolfgang,

Yes you are right. There is now a DEFAULT expression:

Code: Select all

a := b DEFAULT ""
This sets a to b, but if b is NULL then it sets it to ""

Robert

New conditional operator or what?

Posted: Sun Aug 05, 2018 3:31 pm
by Chris
Oops!