tags:

views:

80

answers:

3

Basically, I would like to be able to write a script file (in C# syntax) but then read this into an application so the application will execute the contents of the file.

I don't want the script file to contain the namespaces etc. but the script file will be straight forward C#. For example a script file might look like:

if (Balance == 0 && Withdrawal > 0)
{
    // Don't allow this to happen
}

Basically, like Business Rules but in a script format.

Any ideas or references that I could look at?

+2  A: 

Check this question for information about C# scripting languages.

Drew Noakes
A: 

See here: http://stackoverflow.com/questions/4629/c-eval-equivalent. You have to sanitize the input, otherwise someone can do bad things with it. You might be better off creating a small domain-specific language.

Robert Harvey
A: 

In an application I implemented sucessfully scripting by using the C# compiler and dynamically using the generated code.

You can specify the references to use during compilation and compile one or several files "on-the-fly". You get also the warnings/errors on compilation.

This should be done in a clean fashion with AppDomains but here are a few starters.

A more complex way to use scripting is demonstrated in this "game" where also the security aspects are solved correctly along with the use of AppDomain:

The only aspects I am struggling with are:

  • Debugging of the script
  • If you want to keep it simple, how to find an easy GUI for the script snippets
jdehaan