简体   繁体   English

在运行时执行C#或VB.NET代码

[英]Executing C# or VB.NET code at Runtime

Been spending some time on Codility.com recently and it crossed my mind; 最近在Codility.com上度过了一段时间,它在我脑海中浮现; how do they execute the code you have created (Specifically pertaining to C# and VB.NET) ? 他们如何执行你创建的代码(特别是与C#和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? 另外,您如何防止特别与基于Web的此类程序实施相关的安全违规?

使用CSharpCodeProvider类,您可以在运行时编译代码(作为字符串)。

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. 看看http://msdn.microsoft.com/en-us/library/system.codedom.compiler.aspx在Web应用程序中执行此类代码是一个安全问题。 .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. .Net提供了一组功能来帮助您解决该问题,例如可以将您编译的代码作为不同的用户在不同的应用程序域中运行。

You can compile code in VB.Net and C# at runtime. 您可以在运行时在VB.Net和C#中编译代码。 Have a look at code to do that here 看看这里的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM