How do you do dynamic script evaluation in C#?

Posted by Deane on Stack Overflow See other posts from Stack Overflow or by Deane
Published on 2010-06-16T01:55:20Z Indexed on 2010/06/16 2:02 UTC
Read the original article Hit count: 326

Filed under:
|

What is the state of dynamic code evaluation in C#? For a very advanced feature of an app I'm working on, I'd like the users to be able to enter a line of C# code that should evaluate to a boolean.

Something like:

DateTime.Now.Hours > 12 && DateTime.Now.Hours < 14

I want to dynamically eval this string and capture the result as a boolean.

I tried Microsoft.JScript.Eval.JScriptEvaluate, and this worked, but it's technically deprecated and it only works with Javascript (not ideal, but workable). Additionally, I'd like to be able to push objects into the script engine so that they can be used in the evaluation.

Some resources I find mentioned dynamically compiling assemblies, but this is more overhead than I think I want to deal with.

So, what is the state of dynamic script evaluation in C#? Is it possible, or am I out of luck?

© Stack Overflow or respective owner

Related posts about c#

Related posts about dynamic