简体   繁体   English

动态 C# 代码执行

[英]Dynamic C# code execution

I need to run small snippets of C# code for educational purposes and for each execution, I should open the project (solution), delete existing code, type new code, build and compile, and then run the project.为了教育目的,我需要运行 C# 代码的小片段,对于每次执行,我应该打开项目(解决方案),删除现有代码,键入新代码,构建和编译,然后运行项目。 For example, for executing string.IsNullOrEmpty("something") I should follow all this procedure.例如,为了执行string.IsNullOrEmpty("something")我应该遵循所有这些过程。 I just thought of something like:我只是想到了类似的东西:

在此处输入图像描述

In which I can enter code snippets, click execute, and then see the result.我可以在其中输入代码片段,单击执行,然后查看结果。 Is there anyway to do that?有没有办法做到这一点?

You didn't explicitly state if you're looking for guidance on implementing your own solution or what, but if you're open to using a third party utility then LINQPad is pretty much exactly what you're describing.如果您正在寻找有关实施您自己的解决方案或什么的指导,您并没有明确说明 state,但是如果您愿意使用第三方实用程序,那么LINQPad几乎就是您所描述的。

Take a look at Snippet Compiler .看看片段编译器

Not exactly what you're asking for, but from what I can tell it seems pretty close.不完全是您要求的,但据我所知,它似乎非常接近。

There is also ideone which can run C# code, as well as a large number of other languages.还有ideone可以运行C#代码,以及大量其他语言。

There is also mono's csharp/gsharp:还有mono的csharp/gsharp:

see http://www.mono-project.com/CsharpReplhttp://www.mono-project.com/CsharpRepl

Mono are doing the compiler as service stuff - this is what you are looking for: http://tirania.org/blog/archive/2010/Apr-27.html Mono 将编译器作为服务的东西 - 这就是你要找的东西: http://tirania.org/blog/archive/2010/Apr-27.ZFC35FDC70D5FC69D269883A8EZ7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM