Is there a way to dynamically execute a string in .net, similar to eval() in javascript or dynamic sql in sql?

前端 未结 8 1450
心在旅途
心在旅途 2020-12-05 12:39

Is there a way to dynamically execute code contained in a string using .net 2.0, in a similar way to eval() in javascript or using sp_executeSQL in tsql?

I have a st

8条回答
  •  盖世英雄少女心
    2020-12-05 13:18

    I just ran across something the other day which does just this in another .NET language: http://reverseblade.blogspot.com/2009/02/dont-wait-for-c-5-use-nemerle.html

    I would imagine you could write your string-processing code in nemerle, compile, and reference from your C# or VB app.

    I would still favor an extensible design like casperOne suggests. By doing dynamic scripting, you'll just be pushing compilation into the app and deployment into whatever process gets the programming strings to the app. But it sounds like you have your reasons, so the only other thing I'd consider here is security. Ideally, you want to limit the user as much as possible to just manipulating strings, in which case List-of-Regex seems like a pretty good option.

提交回复
热议问题