Executing C# or VB.NET code at Runtime

回眸只為那壹抹淺笑 提交于 2019-12-05 02:28:35

问题


Been spending some time on Codility.com recently and it crossed my mind; how do they execute the code you have created (Specifically pertaining to C# and VB.NET) ?

What I am basically wondering is how would I take a textbox on a form type some code in it and then run that code? Is this possible without 3rd party tools?

Also how would you prevent security violations specifically pertaining to a web based implementation of such a program?


回答1:


Have a look at http://msdn.microsoft.com/en-us/library/system.codedom.compiler.aspx Executing such code in a web app is in deed a security problem. .Net provides a set of functionalities to help you solve that problem, like the possibility to run your compiled code in a different app domain as a different user.




回答2:


With the CSharpCodeProvider class you can compile code (as a string) during runtime.




回答3:


You can compile code in VB.Net and C# at runtime. Have a look at code to do that here



来源:https://stackoverflow.com/questions/5618218/executing-c-sharp-or-vb-net-code-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!