小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

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

 昵稱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.

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

why use IronJs

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

what problem can be solved

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

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)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多