I came up with a much simpler solution instead.
I built a .dll
file using Javascript and then compiled it using the Javascript compiler which is available in a VS2013 developer command prompt.
Once we have the .dll
we simply add it to the \Support
folder and then referenced it in the project which needed to eval Javascript statements.
Detailed Steps to create a .dll
:
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”)
objResult is True
.