0

Is it possible to call my c# code from a file? The application should be able to scan through the lines in my file and execute the code inside.

Suppose I have the following method in my application:

public void ShowMsg(String msg) 
{
     MessageBox.Show(msg);
}

and the line ShowMsg("Hello") in my file.

I want my application to be able to read the code from file and in the end it should display a message box with the string "Hello". But of course what I'm trying to achieve is way more complicated than simply displaying a message box to the user.

user1295450
  • 167
  • 1
  • 4
  • 8
  • Maybe this can help http://stackoverflow.com/questions/12118077/using-javascript-for-custom-purposes – L.B Sep 22 '12 at 17:28

3 Answers3

3

Here's a tutorial on compiling and executing code at run-time. It should do what you need.

Artless
  • 4,522
  • 1
  • 25
  • 40
0

It is possible, there is an API for it actually.

So here is a link to how you would do it, straight from stackoverflow: Is it possible to dynamically compile and execute C# code fragments?

Community
  • 1
  • 1
Chris
  • 439
  • 7
  • 15
0

sample source in code project: Compiling code during runtime

hamid reza mansouri
  • 11,035
  • 2
  • 22
  • 32