Calling method with Array, Calling method with default value for parameter

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ToRemObjects
{
public class RemObjectsConsole
{
public void writeObject(object value)
{
Console.WriteLine(“writeObject:{0}:{1}”, (null == value ? “<>” : value.GetType().Name), (null == value ? “<>” : value));
}
public void load(string commandText, params object[] parameters)
{
// do something…
int i = 0;
}
public void load2(string commandText, object[] parameters)
{
// do something…
int i = 0;
}
public void loadStrings(params string[] parameters)
{
// do something…
int i = 0;
}
public void loadDoubles(params double[] parameters)
{
// do someting…
int i = 0;
}
public void loadStrings2(string[] parameters)
{
// do something…
int i = 0;
}
public void methodWithDefaults(double p0, double p1 = -1, string p2 = “str”)
{
Console.WriteLine(“methodWithDefaults: p0:{0} p1:{1} p2:{2}”, p0, p1, p2);
}
public void methodNoDefaults(double p0, double p1, string p2)
{
Console.WriteLine(“methodNoDefaults: p0:{0} p1:{1} p2:{2}”, p0, p1, p2);
}
public void methodNoDefaultsDate(DateTime p0)
{
Console.WriteLine(“methodNoDefaultsDate: p0:{0}”, p0);
}
}

class Program
{
    static void Main(string[] args)
    {
        RemObjectsConsole cc = new RemObjectsConsole();



        cc.load(".net no pararameters command");
        cc.load("command text", 1.2, "ss", DateTime.Now, true);
        List<object> list = new List<object>(new object[] { 1.2, "ss", DateTime.Now, true });
        list.Add(100);
        list.Add(101);
        list.Add("fff");
        StringBuilder command = new StringBuilder();
        for (int i = 0, c = list.Count; i < c; i++)
        {
            command.Append("command part " + i);
        }
        cc.load(command.ToString(), list.ToArray());


        using (var esc = new RemObjects.Script.EcmaScriptComponent())
        {
            object o = null;
            esc.Include("test1", @"

function testSomeOthers(cc) {
cc.load(‘no pararameters command’);//here .Net behaviour is to call method with parameters=new object[0];
cc.load(‘command text’, 1.2,‘ss’,new Date(), true);

var a = [1.2,'ss',new Date(), true];
a.push(100);
a.push(101);
a.push('fff');

var cmd = [];
for(var i in a)
    cmd.push('command part ' + i);

cc.load(cmd.join(', '), a); //one parameter of type EcmaScriptArrayObject???

cc.load('some other command', a, a); //two parameters of type EcmaScriptArrayObject, this is OK for me

//cc.load.apply(cc,[1.2,'ss',new Date(), true]); // Exception
//cc.load2('command text', [10, 1.2,'ss',new Date(), true]); //Exception: Object must implement IConvertible.
cc.loadStrings(1.2,'ss',new Date(), true);
cc.loadDoubles(10,1.2,6.7,89.,100);

cc.methodWithDefaults(10, 10);//Error p2 is not 'str' but null
cc.methodWithDefaults(20);//Error p1 is not -1 but zero

cc.methodNoDefaults(10, 10);
cc.methodNoDefaults(20);
cc.methodNoDefaultsDate();

}
");
o = esc.RunFunction(“testSomeOthers”, cc);
Console.ReadLine();
}
}

}

}

Hello

Unfortunately default parameters aren’t supported yet by Script for NET

Is there any plans to support mentioned

  1. Calling methods with array
  2. Methods with default parameters

second is some how tedious to write bunch of methods

Hello.

Corresponding issues are registered as:

  1. 60468: Script: Different behaviour if call function from .NET and JS side
  2. 60473: Script: TypeError: Object RemObjects.Script.EcmaScript.Overloads has no method ‘apply’
  3. 60476: Script: Script: Support function default values.

Thanks.

The “apply” thing is as designed. External functions doesn’t support the Function prototype as i don’t want anyone to modify the self.

I only try to call function with variable number of parameters,
which I collect dynamically and apply can do this with JS Functions,
this is way I try something like that