CLR Type Importing

Enable DirectAccess

To use .NET types in script side, the DirectAccess mode should be set to enable.
srm.WorkMode |= MachineWorkMode.AllowDirectAccess;

Import .NET types in C# side

srm.ImportType(typeof(LinkLabel));

Use the type in script side:
var link = new LinkLabel();

Note: When using ImportType method to import .NET types, ScriptRunningMachine create the standard ECMAScript constructors for each .NET type. The constructor will be attached to the global object 'script', it is same as: function LinkLabel() { }

Import .NET namespaces into script in C# side

Once a .NET namespace has been imported into script context, the types of the namespace are all available for script.
srm.ImportNamespace("System.Windows.Forms");

Enable script to import .NET types

Script can use import keyword to import .NET types. To allow script to do that, the 'AllowImportTypeInScript' must be set to enable:
srm.WorkMode |= MachineWorkMode.AllowImportTypeInScript;

Import .NET types and namespaces in script side

Type or namespace can be imported in script context by using import keyword:
import System.Windows.Forms.Form;   // import type
import System.Drawing.*;            // import namespace and their types

Then Form will be available to script, the instance of Form can be created like call a normal function in script:
var f = new Form();                 // create windows form
f.show();                           // show form

Last edited Jan 17, 2014 at 12:36 PM by unvell, version 7