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. 横竖屏切换时候Activity的生命周期

    1.新建一个Activity,并把各个生命周期打印出来 2.运行Activity,得到如下信息 onCreate-->onStart-->onResume--> 3.按crtl+f1 ...

  2. Inno Setup的使用笔记

    Inno Setup的使用笔记 分类: Install Setup 2013-02-02 15:33 1002人阅读 评论(0) 收藏 举报 项目需要,前些天学习了Inno Setup这跨打包工具的使 ...

  3. [转]BEHAVOUR TREE

    自从开博以来,每天都会关心一下博客的访问情况,看到一些朋友的订阅或者访问,不胜欣喜,也促使我去写一些更好的博文,来和大家分享和交流,从访问 统计来看,有相当一部分是来自于搜索引擎的流量,关键字以“行为 ...

  4. Selenium Waits

    Selenium高级功能包含查找等待, Selenium的查找等待有两种方式, 隐式等待(Implicit Waits)和显示等待(Explicit Waits): 这里写下我对两者的理解, 1. 隐 ...

  5. Smart210学习记录-------linux内核模块

    Linux 驱动工程师需要牢固地掌握 Linux 内核的编译方法以为嵌入式系统构建可运行的Linux 操作系统映像.在编译 LDD6410 的内核时,需要配置内核,可以使用下面命令中的 一个: #ma ...

  6. (实用篇)php处理单文件、多文件上传代码分享

    php处理  单文件.多文件上传实例代码,供大家参考,具体内容如下 后台处理文件submit_form_process.php <?php /************************** ...

  7. 解决:导入第三方jar包后,仍然出现java.lang.NoClassDefFoundError的错误

    最近,在运行某个Android工程的时候,一直抛出java.lang.NoClassDefFoundError异常. 按照异常所给出的信息,应该是程序使用到的第三方jar包出了问题. 但是,这些第三方 ...

  8. C++,栈与队列

    1,头文件 #include <stack> #include <queue> 2,声明 stack<int> stackTest; queue<int> ...

  9. JavaWeb学习记录(二十一)——国际化处理

    ¨国际化又称为 i18n:internationalization ¨对于软件中的菜单栏.导航条.错误提示信息,状态信息等这些固定不变的文本信息,可以把它们写在一个properties文件中,并根据不 ...

  10. 简单三步-实现dede站内搜索功能

    第一步:找到对应的搜索模板的代码 我们都知道,dede有自带的搜索功能,我们只要找到对应的模板,然后把我们想要的代码拿出来就行了.具体如下: 首先进入templets-->default--&g ...