fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: New conditional operator or what?

New conditional operator or what? 10 months 1 week ago #5710

  FFF's Avatar Topic Author FFF Away Posts: 565
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.

New conditional operator or what? 10 months 1 week ago #5711

  Chris's Avatar Chris Offline Posts: 1137
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.

New conditional operator or what? 10 months 1 week ago #5712

  wriedmann's Avatar wriedmann Offline Posts: 1545
Hi Chris,

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

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

New conditional operator or what? 10 months 1 week ago #5713

  robert's Avatar robert Offline Posts: 969
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.

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

Last edit: by robert.

New conditional operator or what? 10 months 1 week ago #5717

  Chris's Avatar Chris Offline Posts: 1137
Oops!
XSharp Development Team
chris(at)xsharp.eu

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

  • Page:
  • 1