xsharp.eu • Optional parameter in VO/c#
Page 1 of 1

Optional parameter in VO/c#

Posted: Wed Oct 25, 2023 4:43 pm
by baramuse
Hi all,

I have this VO function :

Code: Select all

METHOD ArticleListe( Groupe AS STRING, Famille AS STRING, Categorie AS STRING, Offset := 0 AS INT , Limit := -1 AS INT ) AS List<Article>
When I try to call it from c# I have an error :

Code: Select all

_ws.ArticleListe(query.groupe, query.famille, query.categorie);
Error	CS7036	There is no argument given that corresponds to the required parameter 'Offset' of 'ArticleListe(string, string, string, int, int)'
Decompiled code look like

Code: Select all

public List<Article> ArticleListe(string Groupe, string Famille, string Categorie, [DefaultParameterValue(0, 0)] int Offset, [DefaultParameterValue(-1, 0)] int Limit)
Regards.

Re: Optional parameter in VO/c#

Posted: Wed Oct 25, 2023 4:58 pm
by robert
Basile,
VO, Vulcan and X# allow to have default values for optional parameters that are not the last parameter in the list.
Also defaults an be of type DATE or SYMBOL,
To emulate that in .Net where only the last parameters may have optional values, we have added the DefaultParameterValue attribute.
This attribute is a combination of a type flag and a value.
We have also changed the code that takes care of method calls (both in the compiler but also in the late binding code) to convert these attributes back to values.
If you compile X# in the Core dialect, then we will use the C# approach.

If you want to work around this then you can generate overloads and assign the default values in the overloads with less parameters.
Robert