4

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?

1

3 Answers 3

3

You can perform "on-the-fly" compilation.

Check out the following article for more: C#: Writing extendable applications using on-the-fly compilation.

Sign up to request clarification or add additional context in comments.

1 Comment

just the title tells a lot - that's exaclty what i'm lookng for !! on the fly baby :) thanks dude
2

Does the .NET framework have any classes which allow you to run (compile, interpret or whatever) an external script file containing C# code?

Yes, you can use the CodeDomProvider class.

how can i load the code above, from within a winform, app and execute it?

Well,after compile the C# code using the above class,you can use the ProcessStartInfo class and pass it as argument of Start method from Process class and then read the StandardOutput stream,store it on a string and show as you want,Console.Write(), MessageBox.Show() etc.

Comments

2

I would check the Roslyn APIs. You can do what ever you want as long as you provide valid C# o VB.NET code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.