Optional parameter in VO/c#

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

Optional parameter in VO/c#

Post 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.
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Optional parameter in VO/c#

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply