C#使用Jint 函示庫(函數庫/函式庫) 自製 CMD 下可即時測試JavaScript(JS)並取得回饋 應用小軟體
C#使用Jint 函示庫(函數庫/函式庫) 自製 CMD 下可即時測試JavaScript(JS)並取得回饋 應用小軟體
資料來源:
https://github.com/sebastienros/jint
https://www.youtube.com/watch?v=yCs6UmogKEg&t=57s
https://docs.microsoft.com/zh-tw/shows/code-conversations/sebastien-ros-on-jint-javascript-interpreter-net
https://blog.no2don.com/2020/03/cnet-core-c-jint-javascript.html
GITHUB: https://github.com/jash-git/CS_test_jint-project
Code
static void LoadFileCommandMode() { var engine = new Engine(); engine.Execute(System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Script" + Path.DirectorySeparatorChar + "func.js")); while (true) { Console.Write("> "); var Command = Console.ReadLine(); var Result = engine.Execute(Command).GetCompletionValue(); Console.WriteLine(Result); } } static void CommandMode() { var engine = new Engine(); /* //單行JS直譯測試,確定Jint Lib可用 Console.WriteLine(engine.Execute("2+5*12").GetCompletionValue()); */ //* //透過C#無限迴圈,製作一個CMD的可輸入的JS直譯器 // x=12 // y=2 // z=x+y //function add(x,y){return (x+y);} //add(10,20.5) //add(add (10,20),-20.5) while (true) { Console.Write("> "); var Command = Console.ReadLine(); var Result = engine.Execute(Command).GetCompletionValue(); Console.WriteLine(Result); } //*/ }
2 thoughts on “C#使用Jint 函示庫(函數庫/函式庫) 自製 CMD 下可即時測試JavaScript(JS)並取得回饋 應用小軟體”
C# JS(javascript) 實作 直譯器 範例
NUGET Jint (2.11.58) 相關介紹
https://www.nuget.org/packages/Jint/2.11.58
Javascript interpreter for .NET which provides full ECMA 5.1 compliance.
作者: Sebastien Ros
授權: BSD 2-Clause License
發行日: 2017年11月28日 (2017/11/28)
平台支援度:
net5.0
net5.0-windows
net6.0
net6.0-android
net6.0-ios
net6.0-maccatalyst
net6.0-macos
net6.0-tvos
net6.0-windows
net7.0
net7.0-android
net7.0-ios
net7.0-maccatalyst
net7.0-macos
net7.0-tvos
net7.0-windows
net40
net403
net45
net451
net452
net46
net461
net462
net463
net47
net471
net472
net48
相依姓:
.NETFramework 4.5.1
No dependencies.
.NETFramework 4.5
No dependencies.
.NETFramework 4.0
No dependencies.
.NETStandard 2.0
No dependencies.
.NETStandard 1.3
NETStandard.Library (>= 1.6.1)
System.Diagnostics.Contracts (>= 4.3.0)
System.Dynamic.Runtime (>= 4.3.0)
System.Reflection.TypeExtensions (>= 4.4.0)