-
Notifications
You must be signed in to change notification settings - Fork 35
DirectAccess
Jing Lu edited this page Jun 11, 2013
·
15 revisions
ReoScript supports directly to access .Net object in script. The following behavior are available:
- Import .Net classes and namespaces
- Create instance of .Net class
- Access property of .Net instance
- Bind event of .Net instance
By default, ScriptRunningMachine disallows script to access .Net object. To enable DirectAcess, you need to change the WorkMode of ScriptRunningMachine as below:
ScriptRunningMachine srm = new ScriptRunningMachine();
srm.WorkMode |= MachineWorkMode.AllowDirectAccess;
Assume that we have a class in .Net as below:
public class User
{
private string nickname = "no name";
public string Nickname
{
get { return nickname; }
set { nickname = value; }
}
public void Hello()
{
MessageBox.Show(string.Format("Hello {0}!", nickname));
}
}
This User class contains a public property Nickname and a public method Hello, we trying to access this property and call the function in script.
In this demo we create the instance of User class in .Net and put it into script context: (instance can also be created in script, see import keyword.
srm.SetGlobalVariable("guest", new User());
An object named guest was be created and added into script, so now we can use this object:
guest.nickname = 'player1';
guest.hello();
When this script executed, a message box will be displayed.
Hello player1!