0

Possible Duplicate:
How can I evaluate a C# expression dynamically?

Let me describe my issue in an example. There is a string variable in my program:

string func = @"
void printHello()
{
    Console.WriteLine(""Hello world!"");
}
";

Is there any method to let me call this printHello function?

Thanks for any replies.

Community
  • 1
  • 1
adream307
  • 95
  • 1
  • 7

2 Answers2

2

Look at the CS-Script, it's a open source C# Script execution engine

http://www.csscript.net/

Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
0

You can dynamically create and execute code using CodeDomProvider.

Look here for an example: http://blogs.msdn.com/b/digitalnetbizz/archive/2004/01/31/create-assembly-in-memory-and-run-it.aspx

Tisho
  • 8,320
  • 6
  • 44
  • 52