简体   繁体   中英

During runtime: write, compile and use C# code?

Hi I am trying to find a way of executing code generated at runtime, without restarting the program.

My current workflow:

  1. User uses my program to create some diagrams
  2. User presses compile and C# code is generated from the users diagrams
  3. The C# code is placed in a code file which exists in my project's hierarchy. The program is then restarted in order to use the newly generated code.

What I'm after though is changing Step 3, so I don't have to restart the program. Something like:

  1. The C# code is run through the C# compiler which generates a DLL.
    • any errors are shown to the user
  2. The DLL is then loaded into the program
  3. Setup some links to the codes methods, so I can pass data to it and get output data

if this would work?

Look at the CSharpCodeProvider . It is intended for compiling a code in memory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM