Named parameter support

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
baramuse
Posts: 98
Joined: Tue Nov 29, 2022 8:31 am
Location: France

Named parameter support

Post by baramuse »

Hi,

I tried the named parameter syntax

Code: Select all

logConfiguration:WriteTo:File("serilog.txt", rollingInterval := Serilog.RollingInterval.Day ):CreateLogger()
like in the inline constructor of the Tuple example

Code: Select all

 oCustomer := TUPLE{Name := "Nikos", Age := 47, IsActive := TRUE}
but it does not seem to be supported.

Am I doing it wrong ?

Regards.
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Named parameter support

Post by robert »

Basile,
You have to enable the support for this on the language page of the project properties:
https://www.xsharp.eu/help/proppage-language.html

We cannot enable this by default, because the ':=' operator could also be an assignment a rollingInterval local (in your example).
In the Core dialect this is enabled by default. In the other dialects not.

See also https://www.xsharp.eu/help/opt-namedargs.html for an example of where namedarguments could cause a problem.


Rober
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
baramuse
Posts: 98
Joined: Tue Nov 29, 2022 8:31 am
Location: France

Re: Named parameter support

Post by baramuse »

Thank you Robert for the doc.

I did not know you could assign a variable within a method call, so it does make sense.
And you can't use the column either (as in .net) I guess.

Now I have enabled the named parameters, I have hundreds of errors :/
So I'll use the full constructor for that one, but that's good to know !
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Named parameter support

Post by robert »

Basile,
baramuse wrote: Wed Jan 31, 2024 11:49 am Thank you Robert for the doc.

I did not know you could assign a variable within a method call, so it does make sense.
And you can't use the column either (as in .net) I guess.

Now I have enabled the named parameters, I have hundreds of errors :/
So I'll use the full constructor for that one, but that's good to know !
The 100s of errors are the reason that we have disabled this for the non core dialects!

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply