0

我的问题很原始。但它非常有用。我检查了GitHub 上的Sebastien Ros Jint 应用程序。

如何多次 GetValue 属性?

GetValues(x,y,z...)GetValue("x").GetValue("y").GetValue("z")。因为我需要 x,y,z.. 结果。不仅是 x 值。

我有一个项目,我必须运行 js 代码,但有很多 if 比较(注意它不是“if-else”,有 if-if-if 并继续......)我可以访问所有 if陈述结果。我发现有GetValue方法。但我只能访问一个值。当我想访问“y”时,我必须使用GetValue("y"). 但我想同时看到“x”值。也许我渴望那样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());

我在 codeplex 上检查了侏罗纪

我使用它如下:

   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();

问题:

我如何在 myproject 中做到这一点但是使用 Jint 而不是侏罗纪?我需要 Jint multiGetValues 属性...

4

1 回答 1

2

var result = (object[])engine.Execute("[x, y, z]").GetCompletionValue().ToObject(); 您可以从 JavaScript:或动态对象 返回一个数组 dynamic result = engine.Execute("{x, y, z}").GetCompletionValue().ToObject(); Console.WriteLine(result.x);

于 2015-10-19T21:39:36.547 回答