1. Javascript .NET

地址为:http://javascriptdotnet.codeplex.com/

使用方法:

Quick Start

This section provides documentation to get quickly started to embed and run Javascript .NET in your application.

Download Javascript .NET

Download the Javascript .NET latest binary release here. The contained Noesis.Javascript.dll assembly and the Microsoft Runtime Library files in the same directory are all that is required to run Javascript .NET.

Create a new project

Open Visual Studio and create a new Console application.

Reference the Noesis.Javascript assembly from your project

Add a reference to Noesis.Javascript.dll in your project by right clicking on the project and choosing "Add Reference", then select the "Browse" tab, locate the appropriate Noesis.Javascript.dll assembly and click "OK".

Using Noesis.Javascript

Add the following to the "using" statements at the top of you program file:

using Noesis.Javascript;

Initialize a Javascript context

JavascriptContext context = new JavascriptContext()

(Don't forget to Dispose() this object when you are finished with it.)

Set variables in the Javascript context's global scope: SetParameter(string iName, Object iObject);

 context.SetParameter("console", new SystemConsole());
context.SetParameter("message", "Hello World !\n");

Get a parameter from the Javascript context: GetParameter(string iName);

 context.GetParameter("number");

Compile and run the Javascript: Run(string iScript);

context.Run("var i; for (i = 0; i < 5; i++) console.Print(message + ' (' + i + ')'); number += i;");

"Hello World" quick integration sample

A simple integration is shown below. In the sample, a context is created to which a CLI object is supplied to expose the console to the Javascript. A string and an integer are also supplied on which elementary operations are performed. Finally, the resulting value of the supplied integer value is extracted and printed to the console.

Code

    class Program
{
public class SystemConsole
{
public SystemConsole() { } public void Print(string iString)
{
Console.WriteLine(iString);
}
} static void Main(string[] args)
{
// Initialize the context
using (JavascriptContext context = new JavascriptContext()) { // Setting the externals parameters of the context
context.SetParameter("console", new SystemConsole());
context.SetParameter("message", "Hello World !");
context.SetParameter("number", 1); // Running the script
context.Run("var i; for (i = 0; i < 5; i++) console.Print(message + ' (' + i + ')'); number += i;"); // Getting a parameter
Console.WriteLine("number: " + context.GetParameter("number"));
}
}
}

Output

The following will be outputed by the program above:

Hello World ! (0)
Hello World ! (1)
Hello World ! (2)
Hello World ! (3)
Hello World ! (4)
6 2. ClearScript
微软自家的地址为:http://clearscript.codeplex.com/
使用方法:
using System;
using Microsoft.ClearScript;
using Microsoft.ClearScript.V8; // create a script engine
using (var engine = new V8ScriptEngine())
{
// expose a host type
engine.AddHostType("Console", typeof(Console));
engine.Execute("Console.WriteLine('{0} is an interesting number.', Math.PI)"); // expose a host object
engine.AddHostObject("random", new Random());
engine.Execute("Console.WriteLine(random.NextDouble())"); // expose entire assemblies
engine.AddHostObject("lib", new HostTypeCollection("mscorlib", "System.Core"));
engine.Execute("Console.WriteLine(lib.System.DateTime.Now)"); // create a host object from script
engine.Execute(@"
birthday = new lib.System.DateTime(2007, 5, 22);
Console.WriteLine(birthday.ToLongDateString());
"); // use a generic class from script
engine.Execute(@"
Dictionary = lib.System.Collections.Generic.Dictionary;
dict = new Dictionary(lib.System.String, lib.System.Int32);
dict.Add('foo', 123);
"); // call a host method with an output parameter
engine.AddHostObject("host", new HostFunctions());
engine.Execute(@"
intVar = host.newVar(lib.System.Int32);
found = dict.TryGetValue('foo', intVar.out);
Console.WriteLine('{0} {1}', found, intVar);
"); // create and populate a host array
engine.Execute(@"
numbers = host.newArr(lib.System.Int32, 20);
for (var i = 0; i < numbers.Length; i++) { numbers[i] = i; }
Console.WriteLine(lib.System.String.Join(', ', numbers));
"); // create a script delegate
engine.Execute(@"
Filter = lib.System.Func(lib.System.Int32, lib.System.Boolean);
oddFilter = new Filter(function(value) {
return (value & 1) ? true : false;
});
"); // use LINQ from script
engine.Execute(@"
oddNumbers = numbers.Where(oddFilter);
Console.WriteLine(lib.System.String.Join(', ', oddNumbers));
"); // use a dynamic host object
engine.Execute(@"
expando = new lib.System.Dynamic.ExpandoObject();
expando.foo = 123;
expando.bar = 'qux';
delete expando.foo;
"); // call a script function
engine.Execute("function print(x) { Console.WriteLine(x); }");
engine.Script.print(DateTime.Now.DayOfWeek); // examine a script object
engine.Execute("person = { name: 'Fred', age: 5 }");
Console.WriteLine(engine.Script.person.name);
}

.net 开源 JavaScript 解析引擎的更多相关文章

  1. javascript解析引擎(每天有学习一点篇)

    ======================================================= 有一段时间,经常耳闻web前端的福音,对高性能的V8议论纷纷. 其实对js解析引擎没有深 ...

  2. 高性能JavaScript模板引擎原理解析

    随着 web 发展,前端应用变得越来越复杂,基于后端的 javascript(Node.js) 也开始崭露头角,此时 javascript 被寄予了更大的期望,与此同时 javascript MVC ...

  3. 高性能JavaScript模板引擎实现原理详解

    这篇文章主要介绍了JavaScript模板引擎实现原理详解,本文着重讲解artTemplate模板的实现原理,它采用预编译方式让性能有了质的飞跃,是其它知名模板引擎的25.32 倍,需要的朋友可以参考 ...

  4. 20个免费的 JavaScript 游戏引擎分享给开发者

    这篇文章收集了20个免费的 JavaScript 游戏引擎分享给开发者.这些游戏引擎能够帮助游戏开发人员更快速高效的开发出各种好玩的游戏. 使用 HTML5.CSS3 和 Javascript 可以帮 ...

  5. 20 款免费的 JavaScript 游戏引擎

    使用 HTML5,CSS3 和 Javascript 可以帮助面向对象开发者开发拥有各种特性的游戏,比如:3D 动画效果,Canvas,数学,颜色,声音,WebGL 等等.最明显的优势在于使用 HTM ...

  6. JavaScript 模板引擎实现原理解析

    1.入门实例 首先我们来看一个简单模板: <script type="template" id="template"> <h2> < ...

  7. HTML解析引擎:Jumony 开源项目

    Jumony Core首先提供了一个近乎完美的HTML解析引擎,其解析结果无限逼近浏览器的解析结果.不论是无结束标签的元素,可选结束标签的元素,或是标记属性,或是CSS选择器和样式,一切合法的,不合法 ...

  8. 推荐13款javascript模板引擎

    javaScript 在生成各种页面内容时如果能结合一些模板技术,可以让逻辑和数据之间更加清晰,本文介绍 X 款 JavaScript 的模板引擎.(排名不分先后顺序) 1. Mustache 基于j ...

  9. 各种JS模板引擎对比数据(高性能JavaScript模板引擎)

    最近做了JS模板引擎测试,拿各个JS模板引擎在不同浏览器上去运行同一程序,下面是模板引擎测试数据:通过测试artTemplate.juicer与doT引擎模板整体性能要有绝对优势: js模板引擎 Ja ...

随机推荐

  1. Python的"数组"储存

    import time member=["小甲鱼","小布丁","黑夜","迷途","伊静"] pr ...

  2. HDOJ-三部曲-1015-The Cow Lexicon

    The Cow Lexicon Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

  3. 拆解一个简单的KeyFile保护

    系统 : Windows xp 程序 : abexcrackme3 程序下载地址 :http://pan.baidu.com/s/1mh3TiqO 要求 : 伪造Keyfile 使用工具 :IDA 可 ...

  4. Unity3D ShaderLab 布料着色器

    Unity3D ShaderLab布料着色器 布料着色器是我们在虚拟现实中经常使用的着色器.本篇就来完成一个较为简单的布料着色器. 新建Shader,Material,InteractiveCloth ...

  5. Unity3D ShaderLab 简单的立方体图反射

    Unity3D ShaderLab 简单的立方体图反射 反射是着色器模拟现实环境的一个关键因素,它能使我们的着色器渲染效果更加具备视觉冲击,因为他利用了我们周围的环境, 让着色器反射外界的场景信息并将 ...

  6. Smart210学习记录-------文件操作

    一.linux文件操作(只能在linux系统上用) 创建:int creat(const char* filename, mode_t mode) filename 表示要创建的文件名,mode表示对 ...

  7. iOS开发主要参考文档(转载)

    Objective-C,语言的系统详细资料.这是做iOS开发的前题与基础.https://developer.apple.com/library/ios/#documentation/Cocoa/Co ...

  8. 特性节点Attribute

    深入理解DOM节点类型第六篇——特性节点Attribute document.getElementById('b_results').attributes[0].textContent documen ...

  9. 打开office弹出steup error 的解决办法

    找到 C:\Program Files\Common Files\Microsoft Shared\OFFICE12\Office Setup Controller 将这个文件夹删除

  10. win7 通过命令行压缩文件

    1,下载winrar这款软件(可能要正式版) 2,安装完之后在c:\programe files里找到winrar目录,复制winrar目录里的winRar.exe文件到c盘下的windows目录 3 ...