You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the params keyword throws the following exception:
V8ExecutionErrorException: Uncaught Error: Failed to invoke constructor: => Message: Types.ChangeType(): Cannot convert value "Hello" (type: 'System.String') to type 'System.String[]'. If you are developing the source type yourself, implement the 'IConvertible' interface.
Sample:
/// <summary>
/// The MFString field contains zero or more strings.
/// </summary>
[ScriptObject("MFString", ScriptMemberSecurity.NoAcccess)]
public class MFString
{
private List<string> values = new List<string>();
public MFString(params string[] values)
{
this.values.AddRange(values);
}
[ScriptMember("push", ScriptMemberSecurity.Locked)]
private void Push(params string[] values)
{
this.values.AddRange(values);
}
[ScriptMember("toString", ScriptMemberSecurity.Locked)]
public override string ToString()
{
return string.Join(", ", values);
}
}
Engine.RegisterType<MFString>(null, null, ScriptMemberSecurity.Locked);
Engine.GlobalObject.SetProperty(typeof(MFString));
Engine.Execute
(@"
function test() {
var s = new MFString('Hello', 'World');
Browser.println(s);
s.push('!', 'Test', 'Test2');
Browser.println(s);
}
test();
", "V8.NET", true, 0);
The text was updated successfully, but these errors were encountered:
Hi, seems GitHub is unreliable in sending email notices. I just saw this now. The "params" keyword is just sugar in C# for accepting an array of parameters. As far as JavaScript world is concerned, and the binding, an array of strings is expected, not a parameter list (i.e. var s = new MFString(['Hello', 'World']);). I will have to mark this as a todo item and review if this can be supported better, thanks.
Hi James, sorry for the late reply! Unfortunately array parameters don't work as well. Seems like only primitive and registered types get converted correctly. I will do some research and look into this further. Maybe I can come up with a solution that fixes both problems.
Using the params keyword throws the following exception:
V8ExecutionErrorException: Uncaught Error: Failed to invoke constructor: => Message: Types.ChangeType(): Cannot convert value "Hello" (type: 'System.String') to type 'System.String[]'. If you are developing the source type yourself, implement the 'IConvertible' interface.
Sample:
The text was updated successfully, but these errors were encountered: