My current project is an application that allows you to write code in C# and then execute it using CSharpCodeProvider. It works fine at this point as long as the code is a complete application in itself, for example:
using System;
namespace RuntimeCode {
public static class Program {
public static void Main() {
Console.WriteLine("Hello, world!");
}
}
}
The application then compiles the given code using CompileAssemblyFromSource
with GenerateInMemory = true
, and then invoking the Main
method within the compiled assembly.
My question is, how can I let the compiled code access objects in the main application?