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


C# Script.Execute方法代码示例

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


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

示例1: Execute

        public dynamic Execute(Script script)
        {
            if (script == null)
                throw new ArgumentNullException("script");

            return script.Execute(this.executionContext);
        }
开发者ID:smack0007,项目名称:Snowflake,代码行数:7,代码来源:ScriptEngine.cs

示例2: ThrowActualExceptionInsteadOfTargetInvocationException

        public void ThrowActualExceptionInsteadOfTargetInvocationException()
        {
            Script task = new Script();
            task.BuildEngine = new MockBuild();
            task.Code = @"public static void ScriptMain(){
throw new InvalidOperationException(""This is the actual exception."");
}";
            Assert.IsTrue(task.Execute(), "Task should have succeeded.");
        }
开发者ID:464884492,项目名称:msbuildtasks,代码行数:9,代码来源:ScriptTest.cs

示例3: Execute

        public void Execute(Script script)
        {
            if (script == null)
            {
                throw new ArgumentNullException("script");
            }

            script.Execute();
        }
开发者ID:Confluxx,项目名称:ScriptingToolkit,代码行数:9,代码来源:ScriptEngine.cs

示例4: AttemptsToReturnANonStringValue

        public void AttemptsToReturnANonStringValue()
        {
            Script task = new Script();
            task.BuildEngine = new MockBuild();
            task.Code = @"public static int ScriptMain(){
return 4;
}";
            Assert.IsTrue(task.Execute(), "Task should have succeeded.");
            Assert.IsNull(task.ReturnValue, "ReturnValue should only be set when it is a string.");
        }
开发者ID:464884492,项目名称:msbuildtasks,代码行数:10,代码来源:ScriptTest.cs

示例5: SetsReturnValue

        public void SetsReturnValue()
        {
            Script task = new Script();
            task.BuildEngine = new MockBuild();
            task.Code = @"public static string ScriptMain(){
return ""Hello World"";
}";
            Assert.IsTrue(task.Execute(), "Task should have succeeded.");
            Assert.AreEqual("Hello World", task.ReturnValue, "ReturnValue should have been set.");
        }
开发者ID:464884492,项目名称:msbuildtasks,代码行数:10,代码来源:ScriptTest.cs

示例6: Execute

        public void Execute()
        {
            Script task = new Script();
            task.BuildEngine = new MockBuild();
            task.Code = @"public static void ScriptMain(){
int x = 1;
System.Diagnostics.Debug.WriteLine(x);
}";
            Assert.IsTrue(task.Execute(), "Task should have succeeded.");
        }
开发者ID:464884492,项目名称:msbuildtasks,代码行数:10,代码来源:ScriptTest.cs

示例7: ExecuteWithStrongNameReference

        public void ExecuteWithStrongNameReference()
        {
            Script task = new Script();
            task.BuildEngine = new MockBuild();
            task.Code = @"public static void ScriptMain(){
string x = System.Web.HttpUtility.HtmlEncode(""<tag>"");
System.Diagnostics.Debug.WriteLine(x);
}";
            task.References = new ITaskItem[] { new TaskItem("System.Web") };
            Assert.IsTrue(task.Execute(), "Task should have succeeded.");
        }
开发者ID:464884492,项目名称:msbuildtasks,代码行数:11,代码来源:ScriptTest.cs

示例8: ExecuteWithImports

        public void ExecuteWithImports()
        {
            Script task = new Script();
            task.BuildEngine = new MockBuild();
            task.Code = @"public static void ScriptMain(){
int x = 1;
Debug.WriteLine(x);
}";
            task.Imports = new ITaskItem[] { new TaskItem("System.Diagnostics") };
            Assert.IsTrue(task.Execute(), "Task should have succeeded.");
        }
开发者ID:464884492,项目名称:msbuildtasks,代码行数:11,代码来源:ScriptTest.cs

示例9: InitScript

        public string InitScript()
        {
            Script = new Script();

            if (Settings.Script.Length > 0)
            {
                try
                {
                    Script.GlobalsAdd("MGO", MGO);
                    Script.GlobalsAdd("World", this);
                    Script.GlobalsAdd("Session", session);
                    Script.GlobalsAdd("AiEventHandler", aiEventHandler);
                    Script.GlobalsAdd("GetFrameFactor", new GameAI.GetFrameFactorDelegate(GameAI.GetFrameFactor));

                    Script.Execute("lr = littleRunner(MGO, World, Session, AiEventHandler, GetFrameFactor)");
                    Script.GlobalsAdd("lr");

                    foreach (GameObject go in this.AllElements)
                    {
                        if (go.Name != null && go.Name != "")
                        {
                            Script.GlobalsAdd(go.Name, go);
                            Script.Execute("lr.Handler." + go.Name + " = EventAttrDict()");
                        }
                    }

                    Script.Execute("handler = lr.Handler"); // very important! because Script.cs needs access to Globals["handler"].
                    Script.GlobalsAdd("handler");
                    Script.Execute(Settings.Script);
                    Script.Init = false;
                }
                catch (NullReferenceException)
                {
                    return null; // Script closed game!
                }
                catch (Exception e)
                {
                    return e.GetType().FullName + ":\n" + e.Message;
                }
            }

            return "";
        }
开发者ID:andihit,项目名称:littleRunner,代码行数:43,代码来源:World.cs

示例10: ScriptInString

        private void ScriptInString()
        {
            Console.WriteLine("Running script from string...");

            var code = @"
            class script2class:
            def Goodbye(self):
            message = 'Goodbye via the script!'
            return message
            def GoodbyeWithName(self, name):
            message = 'Goodbye ' + name
            return message
            def GoodbyeWithPerson(self, person):
            message = 'Goodbye ' + person.Name
            return message";

            var compiled = new Script();
            compiled.InitializeFromString(code);
            Console.WriteLine(compiled.Execute<string>("script2class", "Goodbye"));

            // single param call
            Console.WriteLine(compiled.Execute<string>("script2class", "GoodbyeWithName", "Paulo"));

            // pass instance of complex type
            var person = new Person { Name = "Paulo Mouat", Address = "Boston" };
            Console.WriteLine(compiled.Execute<string>("script2class", "GoodbyeWithPerson", person));

            // duck typing
            var hasNameLikePerson = new HasNameLikePerson { Name = "HAL", Model = 9000 };
            Console.WriteLine(compiled.Execute<string>("script2class", "GoodbyeWithPerson", hasNameLikePerson));
            Console.WriteLine();
        }
开发者ID:paulomouat,项目名称:spikes,代码行数:32,代码来源:Program.cs

示例11: ScriptInFile

        private void ScriptInFile()
        {
            Console.WriteLine("Running script from file...");

            var script = new Script();
            script.InitializeFromFile(@"..\..\..\Scripts\script1.py");

            // no params call
            Console.WriteLine(script.Execute<string>("script1class", "Hello"));

            // single param call
            Console.WriteLine(script.Execute<string>("script1class", "HelloWithName", "Paulo"));

            // pass instance of complex type
            var person = new Person { Name = "Paulo Mouat", Address = "Boston" };
            Console.WriteLine(script.Execute<string>("script1class", "HelloWithPerson", person));

            // duck typing
            var hasNameLikePerson = new HasNameLikePerson { Name = "HAL", Model = 9000 };
            Console.WriteLine(script.Execute<string>("script1class", "HelloWithPerson", hasNameLikePerson));

            // change field in passed type
            var changeState = new Person { Name = "Paulo Mouat", Address = "Boston" };
            Console.WriteLine("Original state: " + changeState);
            script.Execute<string>("script1class", "ChangeAddress", changeState);
            Console.WriteLine("New state: " + changeState);
            Console.WriteLine();
        }
开发者ID:paulomouat,项目名称:spikes,代码行数:28,代码来源:Program.cs

示例12: RuntimeError

        private void RuntimeError()
        {
            Console.WriteLine("Running script with runtime error...");

            var codeWithRuntimeError = @"
            class script4class:
            def Message(self):
            msg = 1/0
            return msg";

            var compiled = new Script();
            try
            {
                compiled.InitializeFromString(codeWithRuntimeError);
                compiled.Execute<string>("script4class", "Message");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetType() + " - " + e.Message);
            }
            Console.WriteLine();
        }
开发者ID:paulomouat,项目名称:spikes,代码行数:22,代码来源:Program.cs

示例13: ExecutionPerf

        private void ExecutionPerf()
        {
            Console.WriteLine("Measuring execution performance for a large method...");

            const int totalCount = 10000;
            var sw = new Stopwatch();

            const int id = 300;
            var code = GetLargeMethod(id);
            var compiled = new Script();
            compiled.InitializeFromString(code);

            for (var i = 0; i < totalCount; ++i)
            {
                sw.Start();
                compiled.Execute<string>("script300class", "ManyIfStatements", i);
                sw.Stop();
            }

            Console.WriteLine(
                string.Format("Executed script a total of {0} times, in {1} ms, averaging {2} ms per run.",
                totalCount,
                sw.ElapsedMilliseconds,
                1.0 * sw.ElapsedMilliseconds / totalCount
                ));
        }
开发者ID:paulomouat,项目名称:spikes,代码行数:26,代码来源:Program.cs


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