日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

利用IronJs在.NET程序里面跑javascript腳本

 昵稱(chēng)10504424 2013-11-12

what’s dlr

The dynamic language runtime (DLR) is a runtime environment that adds a set of services for dynamic languages to the common language runtime (CLR). The DLR makes it easier to develop dynamic languages to run on the .NET Framework and to add dynamic features to statically typed languages.

Dynamic languages can identify the type of an object at run time, whereas in statically typed languages such as C# and Visual Basic (when you use Option Explicit On) you must specify object types at design time. Examples of dynamic languages are Lisp, Smalltalk, JavaScript, PHP, Ruby, Python, ColdFusion, Lua, Cobra, and Groovy.

這么一堆洋文擺著,也懶的翻譯了。說(shuō)直接一點(diǎn)就是DLR使得.NET有了可以執(zhí)行腳本語(yǔ)言的能力(也許描述的不太精準(zhǔn),不過(guò)你可以這么理解)。

why use IronJs

基于DLR微軟自己開(kāi)了兩套類(lèi)庫(kù)來(lái)跑python跟ruby。不過(guò)我想javascript的通用性更強(qiáng),做程序員的,不過(guò)100%也得有90%寫(xiě)過(guò)javascript吧。

what problem can be solved

那么這種能力有什么好處呢。我能想到的就是對(duì)于系統(tǒng)中一些經(jīng)常需要變更的邏輯,比如折扣算法,積分,以及各種規(guī)則,我們可以提到腳本里去寫(xiě)。這樣不用任何編譯,ctrl+s一下就可以解決問(wèn)題了。

this is demo:

code:

            var jsContext = new IronJS.Hosting.CSharp.Context();
jsContext.ExecuteFile("myDlr.js");
var fun = jsContext.GetFunctionAs<Func<double, double, double>>("cacl");
double a = Double.Parse(this.tbxA.Text);
double b = Double.Parse(this.tbxB.Text);
var result = fun.Invoke(a,b);
this.tbxResult.Text = result.ToString();
 
js:
 
var cacl = function (a, b) {
return a*b;
};

image

當(dāng)我修改a*b為a-b的時(shí)候結(jié)果直接就變成-10了。不用關(guān)閉程序,不用編譯程序,爽。

image

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多