0

I'm trying to figure out if something like this is possible:

string simpleMethod = "public void Hello() { Console.WriteLine(\"Hello\"); }"

ExecuteMethod(simpleMethod);

public void ExecuteMethod(string myMethod) 
{
  //???
}

Expected output:

Hello

I know the above example is probably bad practice, but I am curious to know if it is even possible to do somehow. Any help or insight would be greatly appreciated, thanks.

1 Answers1

0

You can use Roslyn compiler service. Should be part of VS2012 (.Net 4.5) but maybe also available in VS2010 as the CTP was released for it http://blogs.msdn.com/b/visualstudio/archive/2011/10/19/introducing-the-microsoft-roslyn-ctp.aspx

Yakeen
  • 2,142
  • 1
  • 17
  • 21