[Open Source]. Net Dynamic Script Engine NScript,. netnscript

Source: Internet
Author: User

[Open Source]. Net Dynamic Script Engine NScript,. netnscript

Open Source Address: Https://git.oschina.net/chejiangyi/NScript

Open source QQ group:. net open source basic service 238543768

 

. NetDynamic Script Engine NScript

It is used to solve the functions and directions similar to Grovvy in java in. net windows.
Internet projects can be used for some functions, such as dynamic marketing activities (marketing business decoupling and detachment), Rule engines, flow engines, windows O & M scripts, and source code plug-in development.


Usage

The options include exe Main, assembly, and application domain.

Final file Compilation

BSF.BaseService.NScript.exe

ExeDescription
1)Run this exe using the cmd command.
/Run Command Format:/run {filename} {args}

Note: The Main entry function {filename} must be implemented as the file path, and {args} is the Main entry parameter, which is separated by spaces by default.
/Help Command Format:/help

Note: You can view the commands supported by the current exe.
2) exe is the script editor.
It can be used as an editing tool for. net scripts. You can directly edit or temporarily modify the code in the actual running environment. We recommend that you use vs in the development environment.
3) exe itself is also the script runtime.
Parse and run the entire script.
4) exe size
The exe itself is very small, because the third-party editor controls are packaged and merged to make the changes larger.

5) Exe can be referenced by the solution in dll mode, and the NScriptHelper interface method can be used.

 

MainMethod example

Note:

Example of running a script using the exe command
1) Click "run". bat
2) Click "bsf.baseservice.nscript.exe" to edit and debug the script.

:

Download compressed package: Http://share.weiyun.com/043fe46f11aabc1c2c17eb4d7cfa1e00

 

Example of running an assembly or application domain

Description
1)Solution reference "BSF.BaseService.NScript.exe"
2) use the code demo in the Assembly mode and application domain mode.

{This. richTextBox1.Text = @ "public class B {// static void Main (string [] args) // {// System. console. writeLine ("" hello ""); // System. console. readLine (); // System. console. readKey (); //} public string test (string a) {return a ;}}" ;}// set private void button#click (object sender, EventArgs e) {try {string code = this. richTextBox1.Text; CompilerResult result = null; var r = NScriptHelper. run (new CompilerParams () {EnumSourceType = Core. enumSourceType. code, EnumCompilerMode = Core. enumCompilerMode. assembly, CodeOrFileName = code}, "B", "test", new object [] {"a"}, out result); MessageBox. show (r);} catch (Exception exp) {MessageBox. show (exp. message) ;}} // private void button2_Click (object sender, EventArgs e) {try {string code = this. richTextBox1.Text; CompilerResult result = null; var r = NScriptHelper. run (new CompilerParams () {EnumSourceType = Core. enumSourceType. code, EnumCompilerMode = Core. enumCompilerMode. appDomian, CodeOrFileName = code}, "B", "test", new object [] {"a"}, out result); MessageBox. show (r);} catch (Exception exp) {MessageBox. show (exp. message );}}

Download compressed package: Http://share.weiyun.com/5b1f0adf5526b01c7f8ace09eaf9d113

 

Example of editing a script using exe

 

Code main. cs file compiling example

/*

* Codefiles = a. cs, codes \ B. cs; // other compiled code files. Separate multiple files (supporting relative paths). The files are case sensitive (do not include semicolons or equal signs)

* Dllfiles = System. dll; // The referenced dll, that is, the required dll for compilation. Separate multiple dll files (supporting relative paths). It is case sensitive (do not have semicolons or equal signs)

* Compilerlanguage = csharp; // compilation language type. The default value is C #, which can be left empty.

*/

 

/*

* The above compilation header information for the main file must be written to the top of the code file header. Contains source code file information, dll reference information, and code programming language;

Do not use it in the header information unless otherwise specified; and =, which is the Separator Used for parsing. We recommend that you use. main. cs as the end of the main file to automatically identify it. Other code files end with cs.

* The Code content is as follows. net syntax and writing specifications.

* By che jiangyi

*/

UsingSystem;

UsingSystem. Collections. Generic;

UsingSystem. Linq;

UsingSystem. Text;

 

NamespaceMytest // either namespace or

{

PublicClass B

{

// Run in an assembly or application domain

// About debugging: currently, parameter debugging is not supported through "Editor"> "debugging", but the actual environment allows parameter input.

PublicStringTest()

{

ReturnNewC().Test();

}

 

// Specifies the Main entry function for Main compilation.

// About debugging: currently, parameter debugging is not supported through "Editor"> "debugging", but the actual environment allows parameter input.

Static voidMain(String [] args)

{

System. Console.Read();

}

}

}

 

By che jiangyi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.