Reputation: 13
I wonder if there is some method of executing a string, or convert it to a code, example: "Console.WriteLine (\" Hello \ ")";
Equivalent to 'eval' in JavaScript.
I've translated it from Translate Google.
Upvotes: 0
Views: 940
Reputation: 7742
I haven't tried it myself, but it seems what you're looking for is easily feasible using Roslyn ( .Net compiler service )
Take a look at eval()-like for C# using Roslyn and ScriptCS and Hosted Execution of smaller code snippets with Roslyn
Upvotes: 0
Reputation: 11975
You can try cshell: http://cshell.net/
It has a repl-based and executes c# code.
Upvotes: 0
Reputation: 159
I wrote a tutorial on something very similar to this a few years ago - it is based on compiling though:
http://domscode.com/2011/02/16/new-tutorial-tdd-c-web-compiler/
Hope that helps
Upvotes: 0
Reputation: 116137
It is a bit more contrived then using eval
in some languages, but it is certainly possible to programmatically compile code.
Upvotes: 2