-
Notifications
You must be signed in to change notification settings - Fork 35
CLR Type Importing
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.
Set WorkMode to enable DirectAccess:
srm.WorkMode |= MachineWorkMode.AllowDirectAccess;
There are two ways to import the .Net Type into ScriptRunningMachine.
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() { }
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");
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;
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