C#动态执行javascript

Create a file in Notepad with only these contents:

class EvalClass { function Evaluate(expression: String) { return eval(expression); } }
Save the file as C:\MyEval.js

Open a VS2005 Command Prompt (Start, Programs, VS2005, VS2005 Tools)

Type Cd\ to get to C:\

Type

jsc /t:library C:\MyEval.js
A new file is created named MyEval.dll.

Copy MyEval.dll to the project and reference it (also reference Microsoft.Jscript.dll).

Then you should be able to call it like this:

Dim jScriptEvaluator As New EvalClass
Dim objResult As Object
objResult = jScriptEvaluator.Evaluate(“1==1 && 2==2”)
其他方式:https://github.com/davideicardi/DynamicExpresso(支持netcore)

发表评论

电子邮件地址不会被公开。 必填项已用*标注