We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您可以执行类似的操作(使用与此类似的代码创建一个控制台应用程序)
创建此控制台应用程序后,您可以在命令提示符下启动此应用程序:
您可以轻松更改 Main 方法以接受文件而不是内联代码,因此您的控制台应用程序将具有与 python 或 ruby 解释器类似的行为。只需将文件名传递给您的应用程序,然后在主函数中使用 StreamReader 读取它,然后将内容传递给 CompileCode 方法。像这样:
在命令行上:
你必须实现 IRunner 接口,你也可以简单地调用一个硬编码的 Start 方法而不继承该接口,这只是为了展示动态编译类并执行的概念它。
希望有帮助。
You can do something like this (Create a Console app with code similar to this one)
After creating this console app you can start this like this at a command prompt:
You can easily change the Main method to accept file instead of inline code, so your console app would have a simillar behaviour as the python or ruby interpreter. Simply pass a filename to your application and read it with a StreamReader in the main function and pass the content to the CompileCode method. Something like this:
And on the command line:
You have to implement the IRunner interface, you could as well simply call a hard-coded Start method without inheriting the interface, that was just to show the concept of compiling class on the fly and executing it.
Hope it help.
CS-Script:C# 脚本引擎
http://www.csscript.net/
CS-Script: The C# Script Engine
http://www.csscript.net/
将 C# 作为脚本运行的最新且最好的方法是利用 Roslyn。这是用 C# 编写的 C# 编译器。
Glenn Block、Justin Rusbatch 和 Filip Wojcieszyn 将 Roslyn 打包成一个名为
scriptcs
的程序,它完全可以满足您的需求。您可以在这里找到该项目。 http://scriptcs.net/
您可以运行名为
server.csx
的 C# 脚本文件通过致电The latest and best way to run C# as a script is to leverage Roslyn. Which is C# compiler written in C#.
Glenn Block, Justin Rusbatch and Filip Wojcieszyn have packaged up Roslyn into a program, called
scriptcs
, that does exactly what you want.You can find the project here. http://scriptcs.net/
You can run a C# script file called
server.csx
by calling