-1

I wish to be able to write code into an already running program that will compile and implement the code when I hit the send code button on my UI.

For example:

If I type:

MessageBox.Show("Hello World");

and the hit Send, I will get a pop up saying Hello World.

I have searched and searched for ways to this but I can't get any working.

Can anyone recommend a good way to do this?

4
  • Have you read up on codedom? Commented Apr 18, 2013 at 19:04
  • StackOverflow users tend to prefer that you show the ways that you tried and asked for help getting it to work, rather than simply asking how to do it. Commented Apr 18, 2013 at 19:04
  • maybe immediate window? Commented Apr 18, 2013 at 19:09
  • Here is the working example stackoverflow.com/a/74984054/3057246 Commented Jun 29, 2023 at 5:59

2 Answers 2

2

You could use CSharpCodeProvider but it is an older technology and is soon to be outdated.

The latest project Microsoft are toying with is Roslyn, it's currently in CTP and it exposes the compiler and analysis systems used by Microsoft and VStudio etc when building C# and VB.NET apps.

Here's a link on how to use its built in scripting engine.

http://visualstudiomagazine.com/articles/2011/11/16/the-roslyn-scripting-api.aspx

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

1 Comment

This looks like a very interesting article. Thanks for the read!
1

What you are looking for is the CSharpCodeProvider.

This allows you to compile or evaluate C# code from a source and run it. It can do it on the fly and from another process.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.