当前位置: 首页>>代码示例>>C#>>正文


C# ScriptEngine.Evaluate方法代码示例

本文整理汇总了C#中ScriptEngine.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.Evaluate方法的具体用法?C# ScriptEngine.Evaluate怎么用?C# ScriptEngine.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptEngine的用法示例。


在下文中一共展示了ScriptEngine.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CastDoubleToString

 public void CastDoubleToString()
 {
     var script = new ScriptEngine();
     Assert.AreEqual("4", script.Evaluate<string>("string(4.0)"));
     Assert.AreEqual("4.2", script.Evaluate<string>("string(4.2)"));
     Assert.AreEqual("4.2", script.Evaluate<string>("string(4.20)"));
 }
开发者ID:Templarian,项目名称:Script,代码行数:7,代码来源:Cast.cs

示例2: RequireJsCompiler

        public RequireJsCompiler(TextWriter consoleOut, string currentDirectory)
        {
            _jsEngine = new ScriptEngine();
            _jsEngine.CompatibilityMode = CompatibilityMode.ECMAScript3;

            _jsEngine.Evaluate(LoadResource("require.js"));
            _jsEngine.Evaluate(LoadResource("json2.js"));
            _jsEngine.Evaluate(LoadResource(@"adapt\rhino.js"));

            _jsEngine.Evaluate("require(" + new JavaScriptSerializer().Serialize(new {
                baseUrl = ResourceBaseUrl
            }) + ");");

            _fs = new NativeFS(_jsEngine, currentDirectory);
            _jsEngine.SetGlobalValue("YUNoFS", _fs);

            _path = new NativePath(_jsEngine, currentDirectory);
            _jsEngine.SetGlobalValue("YUNoPath", _path);

            _ioAdapter = new IOAdapter(_jsEngine, consoleOut);

            _jsEngine.SetGlobalFunction("load", (Action<string>)_ioAdapter.load);

            _jsEngine.SetGlobalValue("ioe", _ioAdapter);
            _jsEngine.SetGlobalValue("IsRunningYUNoAMD", true);

            SetupModuleFromResource(RequireJsCompiler.ResourceBaseUrl + "env.js", @"build\jslib\env.js");
            SetupModuleFromResource(RequireJsCompiler.ResourceBaseUrl + "yunoamd/args.js", @"build\jslib\yunoamd\args.js");
            SetupModuleFromResource(RequireJsCompiler.ResourceBaseUrl + "build.js", @"build\build.js");
            SetupModuleFromResource(RequireJsCompiler.ResourceBaseUrl + "print.js", @"build\jslib\yunoamd\print.js");
            SetupModuleFromResource(RequireJsCompiler.ResourceBaseUrl + "fs.js", @"build\jslib\yunoamd\fs.js");
            SetupModuleFromResource(RequireJsCompiler.ResourceBaseUrl + "path.js", @"build\jslib\yunoamd\path.js");
            SetupModuleFromResource(RequireJsCompiler.ResourceBaseUrl + "file.js", @"build\jslib\node\file.js");
        }
开发者ID:fschwiet,项目名称:YUNoAMD,代码行数:34,代码来源:RequireJsCompiler.cs

示例3: Scriptable

 public Scriptable()
 {
     engine = new ScriptEngine();
     engine.Evaluate("funcccc = function() { return 3 * 3; }");
     object funccc = engine.GetGlobalValue("funcccc");
     engine.Evaluate("funcccc = function() { return 9 * 9; }");
     loopFuncs = new List<MGFunction>();
     timeAtLastUpdate = System.DateTime.Now;
 }
开发者ID:generatives,项目名称:Magic-Game,代码行数:9,代码来源:Scriptable.cs

示例4: GetMissingPropertyValue

        public void GetMissingPropertyValue()
        {
            var engine = new ScriptEngine();

            // Create a new TestClass1 instance.
            engine.SetGlobalValue("test", new TestClass1(engine));

            // Missing properties should return the name of the property.
            Assert.AreEqual("unknown", engine.Evaluate("test.unknown"));
            Assert.AreEqual("unknown", engine.Evaluate("test['unknown']"));
            Assert.AreEqual("1", engine.Evaluate("test[1]"));

            // Existing properties should still work.
            Assert.AreEqual(1, engine.Evaluate("test.exists"));

            // Missing properties return null for Object.getOwnPropertyDescriptor().
            Assert.AreEqual(Undefined.Value, engine.Evaluate("Object.getOwnPropertyDescriptor(test, 'unknown')"));

            // Missing properties return false from hasOwnProperty().
            Assert.AreEqual(false, engine.Evaluate("test.hasOwnProperty('unknown')"));

            // Missing properties return false from propertyIsEnumerable().
            Assert.AreEqual(false, engine.Evaluate("test.propertyIsEnumerable('unknown')"));

            // Create a new TestClass2 instance.
            engine.SetGlobalValue("test", new TestClass2(engine));

            // Missing properties should return a function which can be called.
            Assert.AreEqual("unknown0", engine.Evaluate("test.unknown()"));
            Assert.AreEqual("unknown1", engine.Evaluate("test.unknown(1)"));
        }
开发者ID:nagyistoce,项目名称:jurassic,代码行数:31,代码来源:ObjectExtensibilityTests.cs

示例5: SetGlobalFunction

        public void SetGlobalFunction()
        {
            var engine = new ScriptEngine();

            // Try a static delegate.
            engine.SetGlobalFunction("add", new Func<int, int, int>((a, b) => a + b));
            Assert.AreEqual(11, engine.Evaluate("add(5, 6)"));

            // Try an instance delegate.
            engine.SetGlobalFunction("global", new Func<object>(() => engine.Global));
            Assert.AreEqual(5, engine.Evaluate("global().parseInt('5')"));
        }
开发者ID:ffarzat,项目名称:Jurassic,代码行数:12,代码来源:ScriptEngineTests.cs

示例6: Evaluate

        public string Evaluate(string javascriptExpression, ScenarioContext scenarioContext)
        {
            var engine = new ScriptEngine();
            string dependencies = GetDependencies(scenarioContext);
            string javascriptToEval = string.Format("var out;  {0};  out = {1};", dependencies, javascriptExpression);

            object returnVal = engine.Evaluate(javascriptToEval);
            if (returnVal is UserDefinedFunction)
            {
                engine.Execute(javascriptToEval);
                return engine.Evaluate("out()").ToString();
            }
            return returnVal.ToString();
        }
开发者ID:AcklenAvenue,项目名称:Pepino,代码行数:14,代码来源:JurassicJavascriptEvaluator.cs

示例7: Specify

        public override void Specify()
        {
            it(".NET methods evaluate scripts within their current context", delegate()
            {
                var engine = new ScriptEngine();

                var evaluator = new NestingEvaluator(engine);

                engine.SetGlobalValue("foo", evaluator);

                var result1 = engine.Evaluate("var x = 16; (function(x) { return foo.evaluateAndDouble1('x');})(2)");
                var result2 = engine.Evaluate("var x = 16; (function(x) { return foo.evaluateAndDouble2('x');})(2)");

                expect(() => (int)result1 == (int)result2 && (int)result1 == 4);
            });
        }
开发者ID:fschwiet,项目名称:YUNoAMD,代码行数:16,代码来源:Jurassic_evaluate_uses_current_context.cs

示例8: PropertyDouble

 public void PropertyDouble()
 {
     var script = new ScriptEngine();
     var test = script.AddClass("Test");
     test.AddProperty("test", 10.0);
     Assert.AreEqual(10.0, script.Evaluate<double>("Test.test"));
 }
开发者ID:Templarian,项目名称:Script,代码行数:7,代码来源:Property.cs

示例9: PropertyBoolTrue

 public void PropertyBoolTrue()
 {
     var script = new ScriptEngine();
     var test = script.AddClass("Test");
     test.AddProperty("test", true);
     Assert.AreEqual(true, script.Evaluate<bool>("Test.test"));
 }
开发者ID:Templarian,项目名称:Script,代码行数:7,代码来源:Property.cs

示例10: ReadAllTasks

        public static ICollection<string> ReadAllTasks(string path)
        {
            var list = new List<string>();

            if (path.EndsWith(".ts"))
            {
                path = path.Replace(".ts", ".js").Replace(".coffee",".js");
            }

            if (!File.Exists(path))
            {
                return list;
            }

            // executes the gulpfile with some little additions :)
            try
            {
                var engine = new ScriptEngine();
                engine.Execute(Resources.gulpInit);
                engine.ExecuteFile(path);

                // reads the evaluated tasks
                ArrayInstance names = (ArrayInstance)engine.Evaluate("tasks");
                foreach (var elem in names.ElementValues)
                {
                    list.Add((string)elem);
                }
            }
            catch (Exception)
            {
                list.Add("Cannot parse gulpfile");
            }

            return list.Distinct().ToList();
        }
开发者ID:brucethwaits,项目名称:GruntLauncher,代码行数:35,代码来源:GulpParser.cs

示例11: PropertyString

 public void PropertyString()
 {
     var script = new ScriptEngine();
     var test = script.AddClass("Test");
     test.AddProperty("test", "Hello World!");
     Assert.AreEqual("Hello World!", script.Evaluate<string>("Test.test"));
 }
开发者ID:Templarian,项目名称:Script,代码行数:7,代码来源:Property.cs

示例12: PropertyInteger

 public void PropertyInteger()
 {
     var script = new ScriptEngine();
     var test = script.AddClass("Test");
     test.AddProperty("test", 10);
     Assert.AreEqual(10, script.Evaluate<int>("Test.test"));
 }
开发者ID:Templarian,项目名称:Script,代码行数:7,代码来源:Property.cs

示例13: Execute

        public ActionResult Execute()
        {
            try
            {
                var script = ReadScriptFromRequestBody();
                // TODO: Check that script is a "function() { ... }".

                var scriptEngine = new ScriptEngine();
                ConfigureScriptEngine(scriptEngine);

                var result = scriptEngine.Evaluate("(" + script + "())");
                if (result == Undefined.Value)
                {
                    Response.ContentType = "application/json";
                    return new EmptyResult();
                }
                // TODO: Check for non-primitive results and convert into a serialization friendly format.
                // However, the result is probably only ever undefined or a boolean. So don't worry for now.
                return Json(result);
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                return Content(ex.ToString(), "text/plain");
            }
        }
开发者ID:nhsevidence,项目名称:witness,代码行数:26,代码来源:RemoteScriptController.cs

示例14: ReadAllTasks

        /// <summary>
        /// Reads all the defined tasks in a Gruntfile whose path is passed as parameter
        /// </summary>
        /// <param name="path">The path of the  file to examine</param>
        /// <returns>A list of tasks</returns>
        public static ICollection<string> ReadAllTasks(string path)
        {
            var list = new List<string>();

            //executes the gruntfile with some little additions :)
            try
            {
                var engine = new ScriptEngine();
                engine.Execute(Resources.Init);
                engine.ExecuteFile(path);
                engine.Execute("module.exports(grunt);");

                //reads the evaluated tasks
                ArrayInstance names = (ArrayInstance)engine.Evaluate("names");
                foreach (var elem in names.ElementValues)
                {
                    list.Add((string)elem);
                }
            }
            catch (Exception) {
                list.Add("Cannot parse Gruntfile");
            }

            return list;
        }
开发者ID:kojoru,项目名称:GruntLauncher,代码行数:30,代码来源:GruntParser.cs

示例15: BigNumber

 public void BigNumber()
 {
     var engine = new ScriptEngine();
     engine.SetGlobalValue("console", new Jurassic.Library.FirebugConsole(engine));
     engine.ExecuteFile(@"..\..\..\Unit Tests\Real-world\Files\bignumber.js");
     engine.EnableDebugging = true;
     Assert.AreEqual("129963294281830400", engine.Evaluate(@"new BigNumber('129963294281830401').subtract(1).toString()"));
 }
开发者ID:paulbartrum,项目名称:jurassic,代码行数:8,代码来源:RealWorldTests.cs


注:本文中的ScriptEngine.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。