// Assume that the B. CS file has been uploaded to the tempdll folder, and the path of the file and the DLL file to be generated is obtained.
String strcs = server. mappath ("tempdll/B. cs ");
String strdll = strcs. substring (0, strcs. lastindexof (".") + ". dll ";
Codedomprovider Cod = New Microsoft. CSHARP. csharpcodeprovider ();
Cod = new Microsoft. CSHARP. csharpcodeprovider ();
Compilerparameters COM = new compilerparameters ();
// Generate DLL. True indicates that the EXE file is generated, and false indicates that the DLL file is generated.
Com. generateexecutable = false;
Com. outputassembly = strdll;
// Generate the CS file into a DLL
Compilerresults Comr = cod. compileassemblyfromfile (COM, strcs );
// Next we can use the generated DLL reflection as the relevant object.
Assembly A = assembly. loadfrom (strdll );
TypeT = A. GetType ("B ");
Object OBJ = activator. createinstance (t );
T. getmethod ("Run"). Invoke (OBJ, null );
// Remarks:
// (1) the reflected. CS file can only reference the system namespace
// (2) We can also directly convert the CS file into a stream reflection.ProgramBut this will greatly slow down the program running.
// (3) Upload the. CS file and generate the. dll file for program reflection, which will reduce the running cost accordingly.