My question is primitive. But it is very useful. I Checked Sebastien Ros Jint application on GitHub.
How can I GetValue property multiple times?
GetValues(x,y,z...)
or GetValue("x").GetValue("y").GetValue("z")
. because I need x,y,z.. result. not only x value.
I have a project that I have to run js codes but there are lots of if comparisons (Be careful it is not "if-else", there are if-if-if and go on...) I have access to all if statement results. I discovered that There is GetValue
method. But I can access only one value. When I want to access "y", I have to use GetValue("y")
. But I want to see "x" value in the same time. Maybe I desire that GetValues("x","y","z"...)
.
var square = new Engine()
.SetValue("x", 3) // define a new variable
.SetValue("y",4)
.Execute(" var isok1=false; var isok2= false; if(3>1) { x * x; isok1=true; } if(2>1) { y * y }").GetValue("y") // execute a statement
.ToObject() // converts the value to .NET
;
Console.WriteLine(square.ToString());
var square = new Engine()
.SetValue("x", 3) // define a new variable
.SetValue("y",4)
.Execute(" var isok1=false; var isok2= false; if(3>1) { x * x; isok1=true; } if(2>1) { y * y } isok1;").GetCompletionValue() // execute a statement
.ToObject() // converts the value to .NET
;
Console.WriteLine(square.ToString());
I checked Jurassic on codeplex
and I used it as below :
var engine = new Jurassic.ScriptEngine();
engine.SetGlobalValue("x", 15);
engine.SetGlobalValue("y", 2);
engine.Execute(@" var isok1=false; var isok2= false; if(3>1) { x=x * x; isok1=true; } if(2>1) { y= y * y; isok2=true; } ");
Console.WriteLine(engine.GetGlobalValue<int>("x"));
Console.WriteLine(engine.GetGlobalValue<int>("y"));
Console.WriteLine(engine.GetGlobalValue<bool>("isok1"));
Console.WriteLine(engine.GetGlobalValue<bool>("isok2"));
Console.ReadKey();
QUESTION:
How can I do that inside of the myproject But using Jint instead of Jurassic? I need Jint multiGetValues property...
You can return an array from JavaScript:
var result = (object[])engine.Execute("[x, y, z]").GetCompletionValue().ToObject();
or a dynamic objectdynamic result = engine.Execute("{x, y, z}").GetCompletionValue().ToObject(); Console.WriteLine(result.x);