A few days ago I saw a story about. NET Dynamic compilation. NET, is very inspired by the dynamic compilation. On this basis I do some encapsulation, in order to make the call simpler, and increase the dynamic code debugging support, the same code only compile once support, code changes automatically recompile, code reference file automatic loading and manual loading functions.
As pictured above, the class Csharpprovider I encapsulate is simple, and here's how some of the public members are used.
Public properties
assemblyFileName: This property specifies the name of the accessory that is generated dynamically after compilation.
CompilerParameters: This property specifies the parameters of the compilation
References: This property specifies the reference in the compiled code. The caller can add its own reference as long as it calls References.add ("Xxx.dll"), and the class is automatically loaded for all references to the System namespace, without the need to join manually. For the user's own component, if the reference file is not manually specified, the class is automatically guessed based on the namespace name.
Sourcecodefileencoding: If compiled as a file, specifies the encoding type of the file.
Public methods
public bool Compile (string code)
Enter a code string and compile
public bool Compilefromfile (string sourcecodefilename)
Compiling the input code file
public Object CreateInstance (string code, String typefullname)