I am building a little Immediate Window like the one in Visual Studio. I simply try to compile the Text in a Textedit. Now my Question: how do i get into the Scope of my running program? Is it possible to change Values or Lists of my programm? Thats my current compile code:
private void SimpleButtonCompileClick(object sender, EventArgs e)
{
CompilerParameters compilerParameters = new CompilerParameters();
compilerParameters.GenerateExecutable = true;
compilerParameters.GenerateInMemory = true;
compilerParameters.TreatWarningsAsErrors = true;
compilerParameters.CompilerOptions = "/nowarn:1633";
String sourceCode = "";
string pattern =
"\s*#pragma\s+reference\s+"(?<path>[^"]*)"\s*";
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(sourceCode, pattern);
if (match.Success)
compilerParameters.ReferencedAssemblies.Add(match.Groups["path"].Value);
// Specify .NET version
Dictionary<string, string> providerOptions =
new Dictionary<string, string>();
providerOptions.Add("CompilerVersion", "v3.5");
CSharpCodeProvider provider = new CSharpCodeProvider(providerOptions);
// Compile source
CompilerResults results = provider.CompileAssemblyFromSource(compilerParameters, new string[] {sourceCode});
// Show errors
if (results.Errors.HasErrors)
{
String errorString = "";
foreach (var err in results.Errors)
errorString += err + "
";
XtraMessageBox.Show(errorString);
}
else
{
// Invoke compiled assembly s entry point
results.CompiledAssembly.EntryPoint.Invoke
(null, new object[0] {});
}
}