請下載這個Assembly。提供了.net3.5和.net4.0版本使用方法1.下載Noesis.Javascript.dll2.Add Referene 加到工程3.運行官方網站上給的Demo 4.建立Console工程
CSJS
後附完整代碼:
運行後可獲得命令列輸出。http://javascriptdotnet.codeplex.com/
這個是對Google's V8 Javascript engine的封裝,最好的Javascript引擎了。有了這個我們就可以將一些現有的Javascirpt代碼引入到C#的代碼中運行了。
Project Description
Javascript .NET integrates Google's V8 Javascript engine and exposes it to the CLI environment. Javascript .NET compiles (at runtime) and executes scripts directly from .NET code. It allows CLI objects to be exposed and manipulated directly from the executed
Javascript.Sample "Hello World" running through Javascript
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Noesis.Javascript;namespace CSJS{ class Program { public class SystemConsole { public SystemConsole() { } public void Print(string iString) { Console.WriteLine(iString); } } static void Main(string[] args) { // Initialize a context JavascriptContext context = new JavascriptContext(); // Setting external parameters for the context context.SetParameter("console", new SystemConsole()); context.SetParameter("message", "Hello World !"); context.SetParameter("number", 1); // Script string script = @" var i; for (i = 0; i < 5; i++) console.Print(message + ' (' + i + ')'); number += i;"; // Running the script context.Run(script); // Getting a parameter Console.WriteLine("number: " + context.GetParameter("number")); } }}