Skip to content
Jing Lu edited this page May 16, 2013 · 7 revisions

ReoScript provides an ability to create and operate an instance of .Net Type in script, after the Type or the Namespace which contains the Type to be imported into ScriptRunningMachine.

Enable DirectAccess

Set WorkMode to enable DirectAccess:

srm.WorkMode |= MachineWorkMode.AllowDirectAccess;

There are two ways to import the .Net Type into ScriptRunningMachine.

Import CLR Type in .Net program

To import CLR Type in .Net program, use the ImportType method of ScriptRunningMachine as below:

srm.ImportType(typeof(LinkLabel));

Once the type was be imported, ReoScript could create the instance of Type in script.

var link = new LinkLabel();

When ImportType be used to import a .Net Type, ScriptRunningMachine creates a standard JavaScript/ECMAScript constructor function which named .Net Type Name. The constructor would be registered in global object as below:

function LinkLabel() { }

Import CLR Namespace in .Net program

Once a .Net namespace was be imported into script, the Types belongs to the namespace are all available for script.

srm.ImportNamespace("System.Windows.Forms");

Enable Importing CLR Type in Script

In another side, script can also be able to request to import specified .Net Type or Namespace. But this works only the WorkMode of ScriptRunningMachine to be set as below:

srm.WorkMode |= MachineWorkMode.AllowImportTypeInScript;

Import CLR Type and Namespace in Script

Type or namespace can be imported in script using import keyword:

import System.Windows.Forms.Form;   // import Type
import System.Drawing.*;            // import Namespace

Then an instance of Form can be created as below:

var f = new Form();                 // create windows form
f.show();                           // show form