-
Notifications
You must be signed in to change notification settings - Fork 35
Property Getter and Setter
Jing Lu edited this page May 16, 2013
·
2 revisions
ObjectValue implements a base type to support object type in ReoScript with a key/value paired property list. ExternalProperty class defines an interface to implement data exchange between script and .Net program.
Once an instance of ExternalProperty be added into ObjectValue instead of value of property, the getter and setter in this interface will be invoked when object to be accessed in script.
The definition to getter and setter of ExternalProperty as below:
Func<object> getter;
Action<object> setter;
Prepare ScriptRunningMachine:
ScriptRunningMachine srm = new ScriptRunningMachine();
Create an object in .Net:
ObjectValue obj = srm.CreateNewObject();
string color = "green";
obj["color"] = new ExternalProperty(
() => { return color; }, // getter
(v) => { color = Convert.ToString(v); } // setter
);
Add object into script:
srm["apple"] = obj;
Then try to get property value in script:
alert(apple.color); // result is green
Change the value:
apple.color = 'yellow'; // string 'color' in .Net will be changed
alert(apple.color);
The result is:
yellow