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.

1

3 Answers 3

3

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

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

Comments

0

sample source in code project: Compiling code during runtime

Comments

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?

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.