I read this answer, which explains how to use the JScript Eval function from C#. It seems that the only way to compile the JsMath.js
file is throught the command line. I would like to create a C# Class Library Project in Visual Studio 2010 and place the JsMath.js
file inside this project, in order to compile also this file when I build the solution.
Asked
Active
Viewed 260 times
0
1 Answers
0
Mark the file as an Embedded Resource in visual studio. Then you can access it in your code:
Assembly.GetExecutingAssembly().GetManifestResourceStream("JsMath.js");
You can then use the JScriptcodeProvider to dynamically compile the js file into an assembly and load it via reflection. I'm not sure that this is better than just pre building JsMath as an assembly and loading it as a reference into your library.
var compiler = new Microsoft.JScript.JScriptCodeProvider();
var parameters = new CompilerParameters(new [] {"/t:library"});
var result = compiler.CompileAssemblyFromSource(parameters, jsMathSource);
var asembly = result.Assembly;
//Load the assembly method via reflection
The compiling bit I got from this post
-
Ok, but if the `GetManifestResourceStream` method returns a `Stream` object, how could I access the `Eval` method of `JsMath.js` file? – enzom83 Aug 28 '14 at 11:07
-
@enzom83 sorry, I misread what the answer was in the question you linked. I updated my answer, but I'm not sure this is easier than just linking that assembly to your Class Project – Vadim Aug 28 '14 at 15:10