嗨 - 我不知道我怎麼能執行從我的應用程序包含的C#代碼用戶提供的字符串。
實施例:
string userProvidedString = "Console.Write("Hello World!")";
ExecuteCode(userProvidedString); // Should output Hello World!
嗨 - 我不知道我怎麼能執行從我的應用程序包含的C#代碼用戶提供的字符串。
實施例:
string userProvidedString = "Console.Write("Hello World!")";
ExecuteCode(userProvidedString); // Should output Hello World!
有一個CSharpCodeProvider類在框架可被利用。 它包含一個CompileAssemblyFromSource解析和編譯字符串中的代碼的方法。
你也可以像查看MSDN上的這篇博客文章:http://blogs.msdn.com/b/dohollan/archive/2010/08/09/programmatically-invoke-the-c-compiler.aspx
這似乎是一個壞主意 – 2011-02-16 23:39:48