Hi all.
I'm posting this in relation to this thread. It's intended to be just a quick intro to using C# as a scripting language instead of a compiled language.
Due to the fact that CLR compiled applications must be accompanied by a compiler, .net languages provide a unique opportunity to compile code on-the-fly. In this case, we're using a compiled executable to call the compiler to compile code we provide at the moment we wish to execute it via Microsoft.CSharp.CSharpCodeProvider(), thus simulating the behavior of a scripting language. There are two engines I've found to accomplish this task:
Ehtyar.
CSScript.zip (9.9 KB)
I'm posting this in relation to this thread. It's intended to be just a quick intro to using C# as a scripting language instead of a compiled language.
Due to the fact that CLR compiled applications must be accompanied by a compiler, .net languages provide a unique opportunity to compile code on-the-fly. In this case, we're using a compiled executable to call the compiler to compile code we provide at the moment we wish to execute it via Microsoft.CSharp.CSharpCodeProvider(), thus simulating the behavior of a scripting language. There are two engines I've found to accomplish this task:
- C# Script for .NET 2.0 is the engine I eventually chose. It is extremely small and relatively simple, therefore is also a cinch to modify.
- CS_Script is the bulkier, yet more feature full of the two, this one provides for caching of the compiled script, and for embedding the "interpreter" itself into any .net application.
- The System, System.IO, System.Text, System.Collections.Generic, and System.Windows.Forms namespaces are included by default, and the necessary assemblies are referenced.
- The full path of the executing script will be provided as the first argument on the command line.
- The code generated from the scripts will be optimized and will not contain any debug information.
- The interpreter will compile code that does not contain a Main(). However, if you provide a Main(), you must also provide an enclosing class { } , and optionally, a namespace { }. This provides for multiple classes or namespaces in a single script.
Ehtyar.
CSScript.zip (9.9 KB)








