0

I have a C# source code in the file (or in text string). How can I use reflection emit to generate and execute this code?

There are so many examples where people generate one class, then add a method etc, but I need top compile-on-the-fly huge piece of C# code, couple kilobytes.

svick
  • 225,720
  • 49
  • 378
  • 501
user3258819
  • 201
  • 2
  • 5

1 Answers1

0

Reflection.Emit is for working with code at the IL level, it knows nothing about how to compile C# source code, so you can't use it for that.

What you can use for this instead is CodeDOM, specifically the CSharpCodeProvider class and its CompileAssemblyFromFile () or CompileAssemblyFromSource() methods.

svick
  • 225,720
  • 49
  • 378
  • 501