开发者

How to run C# code using C# code?

i had asked earlier about the same kind of question but that was in java....

now for the knowledge, i want to know...

is it possible to run the one C# code using ano开发者_如何学Gother C# code?

bcz i know C# is very powerful, so their might be some way to do this.


It's the same sort of deal:

  • Compile the code, e.g. using CSharpCodeProvider
  • Execute the code, e.g. using reflection

If you download Snippy from the C# in Depth web site, you can see a smallish example of this - basically you type in snippets of C# and it can compile and execute them for you.


That is ultimately a runtime feature; in MS .NET, CSharpCodeProvider is the closest you'll get at the moment, although they have mentioned possibly looking at the "compiler as a service" in the future.

If you're happy to use Mono, it already exists , with REPL example.

Usage (from here):

  // First setup the active using statements:
  Evaluator.Run ("using System;");

  Evaluator.Run ("Console.WriteLine (\"Hello, World\");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜