Does the .NET framework have any classes which allow you to run (compile, interpret or whatever) an external script file containing C# code?
For instance, if I have a file Hello.cs
containing this:
class Hello
//This program displays Hello World
{
static public void Main()
{
System.Console.WriteLine("Hello World");
}
}
how can i load the code above, from within a winform, app and execute it?
I'm interested in the load/execute logic; the program could be anything, from a console app to another winform app.
Does Reflection allow this?
I would check the Roslyn APIs. You can do what ever you want as long as you provide valid C# o VB.NET code.
Check out the following article: C#: Writing extendable applications using on-the-fly compilation.
Yes, you can use the CodeDomProvider class.
Well,after compile the C# code using the above class,you can use the
ProcessStartInfo
class and pass it as argument ofStart
method fromProcess
class and then read theStandardOutput
stream,store it on a string and show as you want,Console.Write()
,MessageBox.Show()
etc.